集成接口 开始执行任务的领域层和数据层和UI层的开发啊(待测试)
集成功能 暂停 取消功能 恢复功能的接口的领域层和数据层的开发 下一步待集成到页面上 优化功能,优化了接口异常和未知异常对页面渲染的影响对用户的体验的不好情况。具体通过弹窗友好提示! 优化更新了tcp指示灯点击出现机器状态中添加选中设备的编号 方便用户使用的明白明了!。 优化更新关闭了tcp重连操作内链条中的获取用户设备和切换设备操作项。 调整了获取无人机状态信息的更新频率 为14秒一次
This commit is contained in:
@@ -17,6 +17,7 @@ import '../widgets/device_item_widget.dart';
|
||||
import '../widgets/drone_station_item_card.dart';
|
||||
import 'robot_list_page.dart';
|
||||
import 'drone_station_detail_page.dart';
|
||||
import '../../../../remote_control/presentation/bloc/remote_control_cubit.dart';
|
||||
|
||||
/// 设备状态页面 - 使用 BLoC 模式
|
||||
class DeviceStatusPage extends StatelessWidget {
|
||||
@@ -50,22 +51,35 @@ class DeviceStatusView extends StatelessWidget {
|
||||
child: Scaffold(
|
||||
backgroundColor: const Color(0xFFF7F7F7),
|
||||
body: SafeArea(
|
||||
child:
|
||||
BlocBuilder<
|
||||
DeviceListBloc.DeviceStatusBloc,
|
||||
DeviceListState.DeviceStatusState
|
||||
>(
|
||||
builder: (context, state) {
|
||||
return Column(
|
||||
children: [
|
||||
_buildAppBar(context),
|
||||
_buildSearchBar(context),
|
||||
_buildTypeFilterBar(context),
|
||||
Expanded(child: _buildContent(context, state)),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
child: BlocConsumer<
|
||||
DeviceListBloc.DeviceStatusBloc,
|
||||
DeviceListState.DeviceStatusState
|
||||
>(
|
||||
listener: (context, state) {
|
||||
// 🔥 监听错误状态,显示友好提示
|
||||
if (state is DeviceListState.DeviceStatusError &&
|
||||
state.shouldShowError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.message),
|
||||
duration: const Duration(seconds: 2),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
backgroundColor: Colors.orange,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
return Column(
|
||||
children: [
|
||||
_buildAppBar(context),
|
||||
_buildSearchBar(context),
|
||||
_buildTypeFilterBar(context),
|
||||
Expanded(child: _buildContent(context, state)),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -264,33 +278,11 @@ class DeviceStatusView extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
// 🔥 错误状态不再显示全屏错误页面,而是通过 listener 显示 SnackBar
|
||||
// 页面保持当前内容,用户可以继续操作
|
||||
if (state is DeviceListState.DeviceStatusError) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.error_outline, size: 48, color: Color(0xFF86909C)),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
state.message,
|
||||
style: const TextStyle(fontSize: 14, color: Color(0xFF4E5969)),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
context.read<DeviceListBloc.DeviceStatusBloc>().add(
|
||||
const DeviceListEvent.DeviceStatusLoadData(),
|
||||
);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF165DFF),
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
child: const Text('重试'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
// 如果是从 Loaded 状态变成 Error,返回空容器保持页面
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
if (state is DeviceListState.DeviceStatusLoaded) {
|
||||
@@ -375,7 +367,20 @@ class DeviceStatusView extends StatelessWidget {
|
||||
return BlocProvider(
|
||||
create: (_) =>
|
||||
sl<DroneStationBloc>()..add(DroneStationLoadData(selectedSite.id)),
|
||||
child: BlocBuilder<DroneStationBloc, DroneStationState>(
|
||||
child: BlocConsumer<DroneStationBloc, DroneStationState>(
|
||||
listener: (context, state) {
|
||||
// 🔥 监听错误状态,显示友好提示
|
||||
if (state is DroneStationError && state.shouldShowError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.message),
|
||||
duration: const Duration(seconds: 2),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
backgroundColor: Colors.orange,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
if (state is DroneStationLoading) {
|
||||
return const Center(
|
||||
@@ -383,40 +388,10 @@ class DeviceStatusView extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
// 🔥 错误状态不再显示全屏错误页面,而是通过 listener 显示 SnackBar
|
||||
if (state is DroneStationError) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.error_outline,
|
||||
size: 48,
|
||||
color: Color(0xFF86909C),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
state.message,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: Color(0xFF4E5969),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
context.read<DroneStationBloc>().add(
|
||||
DroneStationLoadData(selectedSite.id),
|
||||
);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF165DFF),
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
child: const Text('重试'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
// 返回空容器保持页面
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
if (state is DroneStationLoaded) {
|
||||
@@ -572,8 +547,11 @@ class DeviceStatusView extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
builder: (BuildContext context) {
|
||||
return BlocProvider.value(
|
||||
value: context.read<DeviceStatusBloc>(),
|
||||
return MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider.value(value: context.read<DeviceStatusBloc>()),
|
||||
BlocProvider.value(value: sl<RemoteControlCubit>()),
|
||||
],
|
||||
child: const DeviceStatusModal(),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -11,9 +11,8 @@ import '../../domain/usecases/update_flight_task_status_usecase.dart';
|
||||
/// 无人机任务与航线控制页面
|
||||
class DroneMissionControlPage extends StatefulWidget {
|
||||
final List<FlightTaskEntity>? selectedTasks;
|
||||
final String? droneSn; // 无人机序列号
|
||||
|
||||
const DroneMissionControlPage({super.key, this.selectedTasks, this.droneSn});
|
||||
const DroneMissionControlPage({super.key, this.selectedTasks});
|
||||
|
||||
@override
|
||||
State<DroneMissionControlPage> createState() =>
|
||||
@@ -23,12 +22,7 @@ class DroneMissionControlPage extends StatefulWidget {
|
||||
class _DroneMissionControlPageState extends State<DroneMissionControlPage> {
|
||||
FlightTaskEntity? _listTask; // 列表数据
|
||||
FlightTaskDetailEntity? _detailTask; // 详情数据
|
||||
String? _droneSn; // 无人机序列号
|
||||
bool _isLoading = false;
|
||||
bool _isReturningHome = false; // 是否正在返航
|
||||
bool _isPausing = false; // 是否正在暂停
|
||||
bool _isReturnHomeLoading = false; // 返航命令是否正在执行
|
||||
bool _isPauseLoading = false; // 暂停命令是否正在执行
|
||||
final Dio _dio = Dio();
|
||||
|
||||
@override
|
||||
@@ -38,7 +32,6 @@ class _DroneMissionControlPageState extends State<DroneMissionControlPage> {
|
||||
_listTask = widget.selectedTasks!.first;
|
||||
_loadTaskDetail();
|
||||
}
|
||||
_droneSn = widget.droneSn; // 初始化无人机序列号
|
||||
}
|
||||
|
||||
Future<void> _loadTaskDetail() async {
|
||||
@@ -78,7 +71,6 @@ class _DroneMissionControlPageState extends State<DroneMissionControlPage> {
|
||||
|
||||
final detailData = jsonData['data'];
|
||||
print('🔍 [DroneMissionControl] data 字段类型: ${detailData.runtimeType}');
|
||||
print('🔍 [DroneMissionControl] data 字段完整内容: $detailData');
|
||||
|
||||
// 确保 data 也是 Map
|
||||
final Map<String, dynamic> detailMap = (detailData is Map)
|
||||
@@ -126,7 +118,7 @@ class _DroneMissionControlPageState extends State<DroneMissionControlPage> {
|
||||
print('❌ [DroneMissionControl] 执行任务失败: ${failure.message}');
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('下发指令失败')));
|
||||
).showSnackBar(SnackBar(content: Text(failure.message)));
|
||||
},
|
||||
(data) {
|
||||
print('✅ [DroneMissionControl] 任务执行成功: $data');
|
||||
@@ -139,105 +131,7 @@ class _DroneMissionControlPageState extends State<DroneMissionControlPage> {
|
||||
print('❌ [DroneMissionControl] 执行任务异常: $e');
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('下发指令失败')));
|
||||
}
|
||||
}
|
||||
|
||||
// 返航/取消返航
|
||||
Future<void> _toggleReturnHome() async {
|
||||
if (_detailTask == null || _detailTask!.sn.isEmpty) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('设备SN不存在')));
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() => _isReturnHomeLoading = true);
|
||||
|
||||
try {
|
||||
final command = _isReturningHome ? 'return_home_cancel' : 'return_home';
|
||||
print('🔍 [DroneMissionControl] 发送返航命令: $command, deviceSn: $_droneSn');
|
||||
|
||||
final response = await _dio.post(
|
||||
HttpApiConsts.flightTaskCommand,
|
||||
data: {'command': command, 'deviceSn': _droneSn},
|
||||
);
|
||||
|
||||
print('📦 [DroneMissionControl] 返航响应: ${response.data}');
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final responseData = response.data;
|
||||
if (responseData['code'] == 0) {
|
||||
setState(() => _isReturningHome = !_isReturningHome);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(_isReturningHome ? '已下发返航命令' : '已取消返航')),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw Exception(responseData['message'] ?? '操作失败');
|
||||
}
|
||||
} else {
|
||||
throw Exception('请求失败');
|
||||
}
|
||||
} catch (e) {
|
||||
print('❌ [DroneMissionControl] 返航操作失败: $e');
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('下发指令失败')));
|
||||
}
|
||||
} finally {
|
||||
setState(() => _isReturnHomeLoading = false);
|
||||
}
|
||||
}
|
||||
|
||||
// 暂停/取消暂停
|
||||
Future<void> _togglePause() async {
|
||||
if (_detailTask == null || _detailTask!.sn.isEmpty) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('设备SN不存在')));
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() => _isPauseLoading = true);
|
||||
|
||||
try {
|
||||
final command = _isPausing ? 'flighttask_recovery' : 'flighttask_pause';
|
||||
print('🔍 [DroneMissionControl] 发送暂停命令: $command, deviceSn: $_droneSn');
|
||||
|
||||
final response = await _dio.post(
|
||||
HttpApiConsts.flightTaskCommand,
|
||||
data: {'command': command, 'deviceSn': _droneSn},
|
||||
);
|
||||
|
||||
print('📦 [DroneMissionControl] 暂停响应: ${response.data}');
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final responseData = response.data;
|
||||
if (responseData['code'] == 0) {
|
||||
setState(() => _isPausing = !_isPausing);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(_isPausing ? '已下发暂停命令' : '已取消暂停')),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw Exception(responseData['message'] ?? '操作失败');
|
||||
}
|
||||
} else {
|
||||
throw Exception('请求失败');
|
||||
}
|
||||
} catch (e) {
|
||||
print('❌ [DroneMissionControl] 暂停操作失败: $e');
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('下发指令失败')));
|
||||
}
|
||||
} finally {
|
||||
setState(() => _isPauseLoading = false);
|
||||
).showSnackBar(SnackBar(content: Text('执行任务失败: $e')));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,7 +256,7 @@ class _DroneMissionControlPageState extends State<DroneMissionControlPage> {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow('网关序列号', task.sn),
|
||||
_buildInfoRow('设备序列号', task.sn),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow('任务类型', task.taskType),
|
||||
const SizedBox(height: 12),
|
||||
@@ -628,7 +522,7 @@ class _DroneMissionControlPageState extends State<DroneMissionControlPage> {
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: _isPauseLoading ? null : _togglePause,
|
||||
onPressed: () {},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFFFF7D00),
|
||||
foregroundColor: Colors.white,
|
||||
@@ -638,28 +532,16 @@ class _DroneMissionControlPageState extends State<DroneMissionControlPage> {
|
||||
),
|
||||
elevation: 0,
|
||||
),
|
||||
child: _isPauseLoading
|
||||
? const SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
_isPausing ? '取消暂停' : '暂停任务',
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
'暂停任务',
|
||||
style: TextStyle(fontSize: 15, fontWeight: FontWeight.w500),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: OutlinedButton(
|
||||
onPressed: _isReturnHomeLoading ? null : _toggleReturnHome,
|
||||
onPressed: () {},
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: const Color(0xFF4E5969),
|
||||
side: const BorderSide(color: Color(0xFFC9CDD4)),
|
||||
@@ -668,19 +550,10 @@ class _DroneMissionControlPageState extends State<DroneMissionControlPage> {
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: _isReturnHomeLoading
|
||||
? const SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: Text(
|
||||
_isReturningHome ? '取消返航' : '返航降落',
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
'返航降落',
|
||||
style: TextStyle(fontSize: 15, fontWeight: FontWeight.w500),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -28,8 +28,10 @@ class DroneStationDetailPage extends StatefulWidget {
|
||||
|
||||
class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
late DroneStationBloc _bloc;
|
||||
UAVDetailEntity? _detail; // 无人机详情数据
|
||||
String? _droneSn; // 无人机序列号
|
||||
|
||||
// 无人机详情数据
|
||||
UAVDetailEntity? _detail;
|
||||
String? _droneSn;
|
||||
|
||||
// 悬浮视频监控状态
|
||||
bool showFloatingMonitor = false;
|
||||
@@ -55,7 +57,7 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
// 加载超时计时器
|
||||
Timer? _floatingLoadingTimer;
|
||||
static const _floatingLoadingTimeout = Duration(seconds: 15);
|
||||
|
||||
|
||||
// 无人机状态轮询计时器
|
||||
Timer? _droneStatusPollingTimer;
|
||||
|
||||
@@ -69,7 +71,7 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
deviceSn: widget.station.deviceSn,
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
// 启动无人机状态轮询(每5秒刷新一次)
|
||||
_startDroneStatusPolling();
|
||||
}
|
||||
@@ -81,15 +83,15 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
debugPrint(' - 是否已显示: $showFloatingMonitor');
|
||||
debugPrint(' - 无人机在线: ${detail.droneOnlineStatus}');
|
||||
debugPrint(' - 机场摄像头: ${detail.gatewayCameraList?.length ?? 0}');
|
||||
|
||||
|
||||
if (!_isFloatingMonitorEnabled || showFloatingMonitor) {
|
||||
debugPrint('❌ 不满足条件,退出检查');
|
||||
return; // 开关关闭或已显示,不执行
|
||||
}
|
||||
|
||||
|
||||
// 无人机在线且有机场摄像头,自动打开悬浮窗
|
||||
if (detail.droneOnlineStatus == 1 &&
|
||||
detail.gatewayCameraList != null &&
|
||||
if (detail.droneOnlineStatus == 1 &&
|
||||
detail.gatewayCameraList != null &&
|
||||
detail.gatewayCameraList!.isNotEmpty) {
|
||||
debugPrint('✅ 检测到无人机在线,自动打开悬浮窗');
|
||||
_loadFloatingVideoStream();
|
||||
@@ -109,13 +111,30 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
|
||||
/// 启动无人机状态轮询
|
||||
void _startDroneStatusPolling() {
|
||||
// 每5秒刷新一次无人机状态
|
||||
_droneStatusPollingTimer = Timer.periodic(const Duration(seconds: 5), (timer) {
|
||||
if (!mounted) {
|
||||
timer.cancel();
|
||||
return;
|
||||
_scheduleDroneStatusPoll();
|
||||
}
|
||||
|
||||
/// 根据无人机状态动态调整轮询周期
|
||||
void _scheduleDroneStatusPoll() {
|
||||
if (!mounted) return;
|
||||
|
||||
// 检查当前无人机状态
|
||||
Duration interval = const Duration(seconds: 60); // 默认60秒
|
||||
final currentState = _bloc.state;
|
||||
if (currentState is UAVDetailLoaded) {
|
||||
if (currentState.detail.droneOnlineStatus == 1) {
|
||||
// 无人机在线时,每15秒轮询一次
|
||||
interval = const Duration(seconds: 15);
|
||||
} else {
|
||||
// 无人机离线时,每60秒轮询一次(降低频率)
|
||||
interval = const Duration(seconds: 60);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_droneStatusPollingTimer?.cancel();
|
||||
_droneStatusPollingTimer = Timer(interval, () {
|
||||
if (!mounted) return;
|
||||
|
||||
debugPrint('🔄 定时刷新无人机状态...');
|
||||
_bloc.add(
|
||||
UAVDetailLoad(
|
||||
@@ -123,17 +142,20 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
deviceSn: widget.station.deviceSn,
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
// 如果悬浮窗开启且无人机上线,自动显示悬浮窗
|
||||
if (_isFloatingMonitorEnabled) {
|
||||
final currentState = _bloc.state;
|
||||
if (currentState is UAVDetailLoaded &&
|
||||
currentState.detail.droneOnlineStatus == 1 &&
|
||||
final state = _bloc.state;
|
||||
if (state is UAVDetailLoaded &&
|
||||
state.detail.droneOnlineStatus == 1 &&
|
||||
!showFloatingMonitor) {
|
||||
debugPrint('✅ 无人机已上线,自动打开悬浮窗');
|
||||
_loadFloatingVideoStream();
|
||||
}
|
||||
}
|
||||
|
||||
// 重新调度下一次轮询(动态周期)
|
||||
_scheduleDroneStatusPoll();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -203,10 +225,7 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
_initFloatingRtcEngine();
|
||||
} else if (state is VideoStreamError) {
|
||||
_floatingLoadingTimer?.cancel();
|
||||
setState(() {
|
||||
_floatingErrorMessage = state.message;
|
||||
_isFloatingLoading = false;
|
||||
});
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
@@ -674,7 +693,6 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
// 悬浮观看功能已禁用
|
||||
// GestureDetector(
|
||||
// onTap: () {
|
||||
@@ -739,10 +757,8 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => DroneMissionControlPage(
|
||||
selectedTasks: tasks,
|
||||
droneSn: _droneSn,
|
||||
),
|
||||
builder: (context) =>
|
||||
DroneMissionControlPage(selectedTasks: tasks),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,20 @@ class _RobotListViewState extends State<RobotListView> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<RobotListBloc, RobotListState>(
|
||||
return BlocConsumer<RobotListBloc, RobotListState>(
|
||||
listener: (context, state) {
|
||||
// 🔥 监听错误状态,显示友好提示
|
||||
if (state is RobotListError && state.shouldShowError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.message),
|
||||
duration: const Duration(seconds: 2),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
backgroundColor: Colors.orange,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
if (state is RobotListLoading) {
|
||||
return const Center(
|
||||
@@ -56,27 +69,10 @@ class _RobotListViewState extends State<RobotListView> {
|
||||
);
|
||||
}
|
||||
|
||||
// 🔥 错误状态不再显示全屏错误页面,而是通过 listener 显示 SnackBar
|
||||
if (state is RobotListError) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.error_outline,
|
||||
size: 48,
|
||||
color: Color(0xFFF53F3F),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'加载失败: ${state.message}',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: Color(0xFF4E5969),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
// 返回空容器保持页面
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
if (state is RobotListLoaded) {
|
||||
@@ -480,9 +476,11 @@ class _RobotListViewState extends State<RobotListView> {
|
||||
status: robot.status,
|
||||
battery: robot.battery,
|
||||
task: robot.task,
|
||||
onTap: () {
|
||||
onTap: () async {
|
||||
// final logger = sl<ILoggerService>();
|
||||
debugPrint('📱 [选中机器人] name: ${robot.name}, id: ${robot.id}, type: ${robot.type}, status: ${robot.status}, battery: ${robot.battery}, task: ${robot.task}');
|
||||
debugPrint('🔴🔴🔴 [选中机器人] ========== 点击事件触发 ==========');
|
||||
debugPrint('🔴🔴🔴 [选中机器人] name: ${robot.name}, id: ${robot.id}, type: ${robot.type}');
|
||||
debugPrint('🔴🔴🔴 [选中机器人] status: ${robot.status}, battery: ${robot.battery}, task: ${robot.task}');
|
||||
|
||||
// 1. 将当前机器人设置为全局待控制设备(用 robot.name 作为 deviceName)
|
||||
final device = DeviceEntity(
|
||||
@@ -495,9 +493,11 @@ class _RobotListViewState extends State<RobotListView> {
|
||||
onlineStatus: robot.status == '在线' ? 1 : 0,
|
||||
);
|
||||
|
||||
debugPrint('🎯 [RobotListPage] 准备调用 setTargetDevice...');
|
||||
// 🔥 使用 GetIt 直接获取 RemoteControlCubit 单例
|
||||
final remoteCubit = GetIt.I<RemoteControlCubit>();
|
||||
remoteCubit.setTargetDevice(device);
|
||||
remoteCubit.setTargetDevice(device); // 🔥 TCP连接在后台异步执行
|
||||
debugPrint('✅ [RobotListPage] setTargetDevice 已调用(TCP连接中)');
|
||||
|
||||
// 2. 跳转到机器人控制页面
|
||||
final robotMap = {
|
||||
@@ -509,6 +509,7 @@ class _RobotListViewState extends State<RobotListView> {
|
||||
'task': robot.task,
|
||||
};
|
||||
|
||||
debugPrint('🚀 [RobotListPage] 准备跳转页面...');
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
|
||||
Reference in New Issue
Block a user