USB 摄像头+远程遥控+中英的适配+topic的集成和状态的使用到相应页面
This commit is contained in:
@@ -7,6 +7,21 @@ import '../../../../devices/presentation/bloc/devices_cubit.dart';
|
||||
import '../../../../devices/domain/entities/device_entity.dart';
|
||||
import '../../../../remote_control/presentation/bloc/remote_control_cubit.dart';
|
||||
import '../../../../remote_control/presentation/pages/remote_control_page.dart';
|
||||
import '../../../../pv_control/presentation/pages/pv_control_page.dart';
|
||||
|
||||
/// 远程遥控入口的控制模式(仅本文件使用)。
|
||||
///
|
||||
/// 保留可扩展:将来要按账号属性动态决定「默认进哪个模式 / 展示哪几个模式」,
|
||||
/// 只需在此枚举增删值即可,不影响前置信息获取与原极简页逻辑。
|
||||
enum _RobotControlMode {
|
||||
minimal('极简模式', '传统远程遥控界面', Icons.videogame_asset_outlined),
|
||||
full('全功能模式', '横屏大屏可视化控制', Icons.grid_view_rounded);
|
||||
|
||||
const _RobotControlMode(this.title, this.subtitle, this.icon);
|
||||
final String title;
|
||||
final String subtitle;
|
||||
final IconData icon;
|
||||
}
|
||||
|
||||
/// 机器人控制面板
|
||||
class RobotControlPanel extends StatelessWidget {
|
||||
@@ -17,7 +32,7 @@ class RobotControlPanel extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
onTap: () async {
|
||||
debugPrint('👆 控制面板被点击');
|
||||
debugPrint('📋 robot 数据: $robot');
|
||||
|
||||
@@ -43,22 +58,41 @@ class RobotControlPanel extends StatelessWidget {
|
||||
// 🔥 在跳转前获取 DevicesCubit,避免在 builder 内部 context 找不到
|
||||
final devicesCubit = context.read<DevicesCubit>();
|
||||
|
||||
// 2. 跳转到远程遥控页面
|
||||
debugPrint('🚀 准备跳转...');
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (newContext) => MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider.value(
|
||||
value: remoteCubit,
|
||||
), // 🔥 复用已设置 targetDevice 的单例
|
||||
BlocProvider.value(value: devicesCubit), // 🔥 同时提供 DevicesCubit
|
||||
],
|
||||
child: const RemoteControlPage(),
|
||||
// 2. 前置信息获取保持不变;进控制页前先选模式:
|
||||
// 极简模式 = 原远程遥控页(RemoteControlPage),全功能模式 = pv_control 大屏。
|
||||
final mode = await _showControlModePicker(context);
|
||||
if (mode == null || !context.mounted) return; // 取消或页面已销毁,不跳转
|
||||
|
||||
if (mode == _RobotControlMode.full) {
|
||||
debugPrint('🚀 [控制面板] 进入全功能模式(pv_control)');
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => PvControlPage(
|
||||
deviceId: device.deviceName,
|
||||
deviceName: device.deviceName,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
} else {
|
||||
debugPrint('🚀 [控制面板] 进入极简模式(远程遥控页)');
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (newContext) => MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider.value(
|
||||
value: remoteCubit,
|
||||
), // 🔥 复用已设置 targetDevice 的单例
|
||||
BlocProvider.value(
|
||||
value: devicesCubit,
|
||||
), // 🔥 同时提供 DevicesCubit
|
||||
],
|
||||
child: const RemoteControlPage(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
@@ -77,7 +111,9 @@ class RobotControlPanel extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
AppLocalizations.of(context).translate('device_list_v2.control_panel'),
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('device_list_v2.control_panel'),
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
@@ -105,22 +141,38 @@ class RobotControlPanel extends StatelessWidget {
|
||||
// 上
|
||||
Positioned(
|
||||
top: 8,
|
||||
child: _buildDirectionButton(context, Icons.arrow_upward, () {}),
|
||||
child: _buildDirectionButton(
|
||||
context,
|
||||
Icons.arrow_upward,
|
||||
() {},
|
||||
),
|
||||
),
|
||||
// 下
|
||||
Positioned(
|
||||
bottom: 8,
|
||||
child: _buildDirectionButton(context, Icons.arrow_downward, () {}),
|
||||
child: _buildDirectionButton(
|
||||
context,
|
||||
Icons.arrow_downward,
|
||||
() {},
|
||||
),
|
||||
),
|
||||
// 左
|
||||
Positioned(
|
||||
left: 8,
|
||||
child: _buildDirectionButton(context, Icons.arrow_back, () {}),
|
||||
child: _buildDirectionButton(
|
||||
context,
|
||||
Icons.arrow_back,
|
||||
() {},
|
||||
),
|
||||
),
|
||||
// 右
|
||||
Positioned(
|
||||
right: 8,
|
||||
child: _buildDirectionButton(context, Icons.arrow_forward, () {}),
|
||||
child: _buildDirectionButton(
|
||||
context,
|
||||
Icons.arrow_forward,
|
||||
() {},
|
||||
),
|
||||
),
|
||||
// 中心按钮
|
||||
Container(
|
||||
@@ -149,17 +201,49 @@ class RobotControlPanel extends StatelessWidget {
|
||||
const SizedBox(height: 12),
|
||||
// 速度档位
|
||||
Text(
|
||||
AppLocalizations.of(context).translate('device_list_v2.speed_gear'),
|
||||
style: TextStyle(fontSize: 13, color: context.appColors.textTertiary),
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('device_list_v2.speed_gear'),
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: context.appColors.textTertiary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: _buildSpeedButton(context, AppLocalizations.of(context).translate('device_list_v2.speed_low'), false, () {})),
|
||||
Expanded(
|
||||
child: _buildSpeedButton(
|
||||
context,
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('device_list_v2.speed_low'),
|
||||
false,
|
||||
() {},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(child: _buildSpeedButton(context, AppLocalizations.of(context).translate('device_list_v2.speed_mid'), true, () {})),
|
||||
Expanded(
|
||||
child: _buildSpeedButton(
|
||||
context,
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('device_list_v2.speed_mid'),
|
||||
true,
|
||||
() {},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(child: _buildSpeedButton(context, AppLocalizations.of(context).translate('device_list_v2.speed_high'), false, () {})),
|
||||
Expanded(
|
||||
child: _buildSpeedButton(
|
||||
context,
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('device_list_v2.speed_high'),
|
||||
false,
|
||||
() {},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -168,6 +252,42 @@ class RobotControlPanel extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// 模式选择弹窗:极简 / 全功能两个选项,选中即返回对应模式,
|
||||
/// 点外部或返回手势取消则返回 null。选项由枚举驱动,仅本文件使用。
|
||||
Future<_RobotControlMode?> _showControlModePicker(BuildContext context) {
|
||||
return showDialog<_RobotControlMode>(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: const Text('选择控制模式'),
|
||||
contentPadding: const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
|
||||
content: SizedBox(
|
||||
width: 320,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
for (final m in _RobotControlMode.values)
|
||||
ListTile(
|
||||
leading: Icon(m.icon, color: context.appColors.primary),
|
||||
title: Text(
|
||||
m.title,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: context.appColors.textPrimary,
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
m.subtitle,
|
||||
style: TextStyle(color: context.appColors.textTertiary),
|
||||
),
|
||||
onTap: () => Navigator.of(dialogContext).pop(m),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDirectionButton(
|
||||
BuildContext context,
|
||||
IconData icon,
|
||||
@@ -216,9 +336,7 @@ class RobotControlPanel extends StatelessWidget {
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: isSelected
|
||||
? Colors.white
|
||||
: context.appColors.textSecondary,
|
||||
color: isSelected ? Colors.white : context.appColors.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user