集成双 MQTT 客户端实现设备实时数据监控(未测试)
1.集成两个独立的 MQTT 客户端,支持 WebSocket 和 TCP 协议 2.实现无人机/机场 OSD 实时监控(ws://1.95.137.212:8083/mqtt) 3.实现任务状态消息订阅(tcp://1.95.137.212:59020) 4.采用清洁架构设计,分层清晰(Domain → Data → Presentation)
This commit is contained in:
@@ -10,6 +10,7 @@ import 'package:maibu_satabot_v2/features/devices/presentation/bloc/devices_cubi
|
||||
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/devices_state.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/device_status_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/device_status_state.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/presentation/bloc/remote_control_cubit.dart'; // 🔥 添加 RemoteControlCubit
|
||||
|
||||
class MachineDetailsPage extends StatefulWidget {
|
||||
final DeviceEntity? device;
|
||||
@@ -157,7 +158,15 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
Navigator.pop(context);
|
||||
if (context.mounted) {
|
||||
final username = context.read<AppUserCubit>().state.user?.username ?? "";
|
||||
context.read<DevicesCubit>().fetchAllDevices(username);
|
||||
|
||||
// 🔥 修复:检查是否已有 targetDevice
|
||||
final remoteControlState = context.read<RemoteControlCubit>().state;
|
||||
if (remoteControlState.targetDevice == null) {
|
||||
debugPrint('🔄 [MachineDetails] 无 targetDevice,开始加载设备列表');
|
||||
context.read<DevicesCubit>().fetchAllDevices(username);
|
||||
} else {
|
||||
debugPrint('✅ [MachineDetails] 已有 targetDevice: ${remoteControlState.targetDevice!.deviceName},跳过加载');
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
@@ -187,7 +196,14 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
Navigator.pop(context);
|
||||
if (context.mounted) {
|
||||
final username = context.read<AppUserCubit>().state.user?.username ?? "";
|
||||
context.read<DevicesCubit>().fetchAllDevices(username);
|
||||
// 🔥 修复:检查是否已有 targetDevice
|
||||
final remoteControlState = context.read<RemoteControlCubit>().state;
|
||||
if (remoteControlState.targetDevice == null) {
|
||||
debugPrint('🔄 [MachineDetails AppBar] 无 targetDevice,开始加载设备列表');
|
||||
context.read<DevicesCubit>().fetchAllDevices(username);
|
||||
} else {
|
||||
debugPrint('✅ [MachineDetails AppBar] 已有 targetDevice: ${remoteControlState.targetDevice!.deviceName},跳过加载');
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
@@ -612,7 +628,15 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
).showSnackBar(SnackBar(content: Text(AppLocalizations.of(context).translate('machine_details.unbind_success').replaceAll('%s', _deviceName)), backgroundColor: Colors.green, duration: const Duration(seconds: 2)));
|
||||
|
||||
final username = context.read<AppUserCubit>().state.user?.username ?? "";
|
||||
context.read<DevicesCubit>().fetchAllDevices(username);
|
||||
|
||||
// 🔥 修复:检查是否已有 targetDevice
|
||||
final remoteControlState = context.read<RemoteControlCubit>().state;
|
||||
if (remoteControlState.targetDevice == null) {
|
||||
debugPrint('🔄 [MachineDetails Unbind] 无 targetDevice,开始加载设备列表');
|
||||
context.read<DevicesCubit>().fetchAllDevices(username);
|
||||
} else {
|
||||
debugPrint('✅ [MachineDetails Unbind] 已有 targetDevice: ${remoteControlState.targetDevice!.deviceName},跳过加载');
|
||||
}
|
||||
}
|
||||
} else if (state.errorMessage?.isNotEmpty == true && !state.isLoading) {
|
||||
if (context.mounted) {
|
||||
@@ -636,9 +660,9 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
}
|
||||
|
||||
// 处理结果:放宽条件,只要无错误信息就认为成功(不管loading)
|
||||
print(
|
||||
"处理修改名称结果,operationType: ${state.operationType}, isLoading: ${state.isLoading}, errorMessage: ${state.errorMessage},state.errorMessage?.isEmpty: ${state.errorMessage?.isEmpty}",
|
||||
);
|
||||
// print(
|
||||
// "处理修改名称结果,operationType: ${state.operationType}, isLoading: ${state.isLoading}, errorMessage: ${state.errorMessage},state.errorMessage?.isEmpty: ${state.errorMessage?.isEmpty}",
|
||||
// );
|
||||
|
||||
// 核心修改:去掉!state.isLoading的判断
|
||||
if (state.errorMessage?.isEmpty == true) {
|
||||
|
||||
Reference in New Issue
Block a user