远程遥控界面编写
This commit is contained in:
@@ -13,7 +13,7 @@ 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/top_status_bar.dart';
|
||||
|
||||
class RemoteControlPage extends StatefulWidget {
|
||||
const RemoteControlPage({super.key});
|
||||
@@ -26,17 +26,17 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// 强制横屏与沉浸式
|
||||
// 1. 锁定横屏
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.landscapeLeft,
|
||||
DeviceOrientation.landscapeRight,
|
||||
]);
|
||||
// 2. 隐藏状态栏和虚拟按键
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// 恢复竖屏
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
super.dispose();
|
||||
@@ -44,16 +44,12 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// 1. 监听全局状态 (实现方案二:掉线实时刷新)
|
||||
// 监听全局状态(这些通常不随摇杆频繁变化)
|
||||
final userState = context.watch<AppUserCubit>().state;
|
||||
final deviceState = context.watch<DevicesCubit>().state;
|
||||
final currentDevice = deviceState.selectedDevice;
|
||||
|
||||
// 2. 监听局部遥控状态 (对应 Android Compose 的 collectAsState)
|
||||
final remoteState = context.watch<RemoteControlCubit>().state;
|
||||
|
||||
// 如果设备突然掉线,显示遮罩 (对应 Android 的 finishEvent 逻辑)
|
||||
if (currentDevice == null /*|| !currentDevice.isOnline*/ ) {
|
||||
if (currentDevice == null) {
|
||||
return _buildOfflineScaffold();
|
||||
}
|
||||
|
||||
@@ -61,56 +57,99 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
backgroundColor: Colors.black,
|
||||
body: Stack(
|
||||
children: [
|
||||
// 底层:视频流 (传入 device 和 user)
|
||||
// 【优化层 1】底层视频:传入固定参数,加上 RepaintBoundary
|
||||
Positioned.fill(
|
||||
child: MyVideoPlayer(
|
||||
deviceIp: TCPConsts.TCP_IP,
|
||||
device: currentDevice,
|
||||
user: userState.user!, // 假设 AppUserCubit 存有 user 实体
|
||||
user: userState.user!,
|
||||
),
|
||||
),
|
||||
|
||||
// 中层:急停呼吸灯光晕 (对应 Android 的 EmergencyBreathingOverlay)
|
||||
if (remoteState.isEmergency)
|
||||
const Positioned.fill(child: EmergencyOverlay()),
|
||||
// 【优化层 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();
|
||||
},
|
||||
),
|
||||
|
||||
// 顶层:UI 控制层
|
||||
// 【优化层 3】顶层:UI 控制层
|
||||
SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
// 顶部胶囊状态条
|
||||
const TopStatusBar(),
|
||||
|
||||
// 左右摇杆及中间控制区
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 20,
|
||||
vertical: 10,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
// 左摇杆:前后控制
|
||||
LeftJoystickArea(isLocked: remoteState.isLocked),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final double sideAreaWidth = constraints.maxWidth * 0.25;
|
||||
final double centerAreaWidth = constraints.maxWidth * 0.5;
|
||||
|
||||
// 中间区:底盘升降/急停按钮
|
||||
const CenterControlArea(),
|
||||
// 关键:使用 BlocBuilder 局部刷新摇杆,不要 watch 整个 Page
|
||||
return BlocBuilder<RemoteControlCubit, RemoteControlState>(
|
||||
// 只有 isLocked 改变时才重构摇杆区域,摇杆坐标改变由内部处理
|
||||
buildWhen: (p, c) => p.isLocked != c.isLocked,
|
||||
builder: (context, remoteState) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
// 左摇杆
|
||||
SizedBox(
|
||||
width: sideAreaWidth,
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: LeftJoystickArea(
|
||||
isLocked: remoteState.isLocked,
|
||||
width: sideAreaWidth * 0.5 * 0.7,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// 右摇杆:左右控制
|
||||
RightJoystickArea(isLocked: remoteState.isLocked),
|
||||
],
|
||||
),
|
||||
// 中间区
|
||||
SizedBox(
|
||||
width: centerAreaWidth,
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: CenterControlArea(totalWidth: centerAreaWidth),
|
||||
),
|
||||
),
|
||||
|
||||
// 右摇杆
|
||||
SizedBox(
|
||||
width: sideAreaWidth,
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: RightJoystickArea(
|
||||
isLocked: remoteState.isLocked,
|
||||
width: sideAreaWidth * 0.5 * 0.7,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// 权限请求弹窗 (对应 Android 的 PermissionRequestDialog)
|
||||
if (remoteState.showPermissionRequestDialog)
|
||||
_buildPermissionDialog(context, remoteState),
|
||||
// 权限弹窗
|
||||
BlocBuilder<RemoteControlCubit, RemoteControlState>(
|
||||
buildWhen: (p, c) => p.showPermissionRequestDialog != c.showPermissionRequestDialog,
|
||||
builder: (context, state) {
|
||||
if (state.showPermissionRequestDialog) {
|
||||
return _buildPermissionDialog(context, state);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user