解决了渲染TCP推送数据,在切换功能后不稳定问题,保证了APP端的稳定性。
This commit is contained in:
@@ -185,13 +185,15 @@ Future<void> init() async {
|
||||
sl.registerLazySingleton(() => AppUserCubit()); // AuthCubit 依赖它,必须先注册
|
||||
sl.registerLazySingleton(() => GetDeviceLocationUseCase(sl()));
|
||||
sl.registerLazySingleton(() => DevicesCubit(sl(), sl(), sl(), sl(), sl(), sl(), sl(), sl(), sl(), sl(), sl(), sl(),sl(),sl(),sl()));
|
||||
sl.registerFactory(() => RemoteControlCubit(sl(),sl(),sl()));
|
||||
/* // 工厂模式(留存,每次获取新实例)r
|
||||
|
||||
sl.registerFactory(() => DeviceStatusBloc(sl<NetMessageDispatcher>()));
|
||||
*/
|
||||
//单例模式(全局共享一个实例)
|
||||
sl.registerLazySingleton(() => DeviceStatusBloc(sl<NetMessageDispatcher>()));
|
||||
|
||||
// 🔥 DeviceStatusBloc 必须在 RemoteControlCubit 之前注册(单例)
|
||||
sl.registerLazySingleton(() => DeviceStatusBloc(
|
||||
sl<NetMessageDispatcher>(),
|
||||
client: sl<TcpClient>(), // 🔥 传入 TcpClient
|
||||
));
|
||||
|
||||
// 🔥 RemoteControlCubit 注入 DeviceStatusBloc(工厂模式,每次新建)
|
||||
sl.registerFactory(() => RemoteControlCubit(sl(), sl(), sl(), sl()));
|
||||
|
||||
/// . 路径生成
|
||||
sl.registerLazySingleton<PathHttpDatasource>(
|
||||
|
||||
@@ -88,6 +88,27 @@ class NetMessageDispatcher {
|
||||
}
|
||||
});
|
||||
}
|
||||
//机器状态页面专用
|
||||
Stream<String> onStringMessageOfdeviceStatus() {
|
||||
//print("0x02--TCP拦截推送解析开始");
|
||||
_logger.log('0x02--TCP拦截推送解析开始');
|
||||
// 🔥 关键修复:使用asBroadcastStream()确保多个监听者都能收到数据
|
||||
return onCommand(0x02).map((p) {
|
||||
try {
|
||||
// 尝试解码
|
||||
final result = utf8.decode(p.payload, allowMalformed: true); // 允许乱码,防止报错中断流
|
||||
//print('✅ 解码 0x02 成功:$result'); // 🔥 关键日志:看这里打印了吗?
|
||||
_logger.log('✅ 解码 0x02 成功:$result');
|
||||
return result;
|
||||
} catch (e) {
|
||||
// print('❌ 解码 0x02 失败:$e, 原始字节:${p.payload}');
|
||||
_logger.log('❌ 解码 0x02 失败:$e, 原始字节:${p.payload}');
|
||||
return ''; // 返回空字符串,避免流中断
|
||||
}
|
||||
}).asBroadcastStream();
|
||||
/* ///return onCommand(0x02).map((p) => utf8.decode(p.payload));*/
|
||||
}
|
||||
|
||||
|
||||
//监听路径规划的开始作业的指令的应答
|
||||
|
||||
|
||||
Reference in New Issue
Block a user