远程遥控开发中
This commit is contained in:
@@ -11,9 +11,9 @@ import '../bloc/remote_control_state.dart';
|
||||
import '../widgets/center_control_area.dart';
|
||||
import '../widgets/emergency_overlay.dart';
|
||||
import '../widgets/left_joystick_area.dart';
|
||||
import '../widgets/my_video_player.dart';
|
||||
import '../widgets/right_joystick_area.dart';
|
||||
import '../widgets/top_status_bar.dart';
|
||||
import '../widgets/webrtc/webrtc_local_player.dart';
|
||||
|
||||
class RemoteControlPage extends StatefulWidget {
|
||||
const RemoteControlPage({super.key});
|
||||
@@ -57,24 +57,35 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
backgroundColor: Colors.black,
|
||||
body: Stack(
|
||||
children: [
|
||||
// 【优化层 1】底层视频:传入固定参数,加上 RepaintBoundary
|
||||
// 在 Stack 的最底层替换:
|
||||
Positioned.fill(
|
||||
child: MyVideoPlayer(
|
||||
deviceIp: TCPConsts.TCP_IP,
|
||||
device: currentDevice,
|
||||
user: userState.user!,
|
||||
child: BlocBuilder<RemoteControlCubit, RemoteControlState>(
|
||||
// 只有当显示隐藏状态改变时才重构,内部的拖拽由组件自身 State 处理,不影响这里
|
||||
buildWhen: (p, c) =>
|
||||
p.showLeftPip != c.showLeftPip ||
|
||||
p.showRightPip != c.showRightPip,
|
||||
builder: (context, state) {
|
||||
return WebRTCLocalPlayer(
|
||||
// 这里的 URL 拼接根据你的后端规则
|
||||
// streamUrl: "webrtc://${TCPConsts.TCP_IP}/live/livestream/${currentDevice.deviceName}?token=${userState.user!.token}",
|
||||
streamUrl:
|
||||
"webrtc://${TCPConsts.TCP_IP}/live/livestream/111?token=${userState.user!.token}",
|
||||
showLeftPip: state.showLeftPip, // 从 Cubit 状态中读取
|
||||
showRightPip: state.showRightPip, // 从 Cubit 状态中读取
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
// 【优化层 2】中层:急停效果(只在 isEmergency 变化时才触发显示/隐藏)
|
||||
BlocBuilder<RemoteControlCubit, RemoteControlState>(
|
||||
buildWhen: (p, c) => p.isEmergency != c.isEmergency,
|
||||
builder: (context, state) {
|
||||
return state.isEmergency ? const Positioned.fill(child: EmergencyOverlay()) : const SizedBox.shrink();
|
||||
return state.isEmergency
|
||||
? const Positioned.fill(child: EmergencyOverlay())
|
||||
: const SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
|
||||
// 【优化层 3】顶层:UI 控制层
|
||||
SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
@@ -86,7 +97,10 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
final double centerAreaWidth = constraints.maxWidth * 0.5;
|
||||
|
||||
// 关键:使用 BlocBuilder 局部刷新摇杆,不要 watch 整个 Page
|
||||
return BlocBuilder<RemoteControlCubit, RemoteControlState>(
|
||||
return BlocBuilder<
|
||||
RemoteControlCubit,
|
||||
RemoteControlState
|
||||
>(
|
||||
// 只有 isLocked 改变时才重构摇杆区域,摇杆坐标改变由内部处理
|
||||
buildWhen: (p, c) => p.isLocked != c.isLocked,
|
||||
builder: (context, remoteState) {
|
||||
@@ -113,7 +127,9 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
width: centerAreaWidth,
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: CenterControlArea(totalWidth: centerAreaWidth),
|
||||
child: CenterControlArea(
|
||||
totalWidth: centerAreaWidth,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -142,7 +158,8 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
|
||||
// 权限弹窗
|
||||
BlocBuilder<RemoteControlCubit, RemoteControlState>(
|
||||
buildWhen: (p, c) => p.showPermissionRequestDialog != c.showPermissionRequestDialog,
|
||||
buildWhen: (p, c) =>
|
||||
p.showPermissionRequestDialog != c.showPermissionRequestDialog,
|
||||
builder: (context, state) {
|
||||
if (state.showPermissionRequestDialog) {
|
||||
return _buildPermissionDialog(context, state);
|
||||
|
||||
Reference in New Issue
Block a user