完成远程遥控页面的优化,包括 折叠功能栏 点击振动反馈 ,急停的读秒进度条 ,左右的振动反馈 ,锁屏的功能按钮的开发(禁用上下左右的滑轮)
This commit is contained in:
@@ -18,6 +18,7 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
Timer? _timer;
|
||||
StreamSubscription? _kickOutSub; // 新增:用于管理监听生命周期
|
||||
final NetMessageDispatcher dispatcher;
|
||||
StreamSubscription? _deviceStatusSub;//🔥 新增:用于监听 DeviceStat
|
||||
|
||||
RemoteControlCubit(this._repository, this._requestControlPermissionUseCase, this.dispatcher)
|
||||
: super(
|
||||
@@ -30,6 +31,59 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
|
||||
}
|
||||
|
||||
// 🔥 新增:监听 DeviceStatusBloc 的状态更新
|
||||
void subscribeToDeviceStatus(Stream deviceStatusStream) {
|
||||
_deviceStatusSub?.cancel();
|
||||
|
||||
_deviceStatusSub = deviceStatusStream.listen((deviceState) {
|
||||
try {
|
||||
// 🔥 关键:从 DeviceStatusBloc 的 state 中提取数据
|
||||
// 这里假设 deviceState 是 DevicesCubit 的 state
|
||||
// 你需要根据实际的 DevicesCubit state 类型来调整
|
||||
|
||||
debugPrint('📡 [收到设备状态更新] deviceState: $deviceState');
|
||||
|
||||
// 如果 DevicesCubit 的 state 中有 runningStatusModel 或类似字段
|
||||
// 方式 1:直接同步整个 RunningStatusModel
|
||||
if (deviceState is Map && deviceState.containsKey('runningStatusModel')) {
|
||||
final newStatus = deviceState['runningStatusModel'] as RunningStatusModel;
|
||||
_updateStatusFromDevice(newStatus);
|
||||
}
|
||||
// 方式 2:如果 DevicesCubit 直接暴露 voltage, battery 等字段
|
||||
else if (deviceState is Map) {
|
||||
final voltage = deviceState['voltage'] as int? ?? 0;
|
||||
final battery = deviceState['battery'] as int? ?? 0;
|
||||
|
||||
emit(state.copyWith(
|
||||
voltage: voltage,
|
||||
battery: battery,
|
||||
));
|
||||
|
||||
debugPrint('📡 [同步设备状态] 电压:${voltage}V, 电量:${battery}%');
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('❌ [同步设备状态失败] $e');
|
||||
}
|
||||
});
|
||||
|
||||
debugPrint('✅ [DeviceStatus] 已建立监听');
|
||||
}
|
||||
|
||||
|
||||
// 🔥 辅助方法:更新运行状态
|
||||
void _updateStatusFromDevice(RunningStatusModel newStatus) {
|
||||
if (!isClosed) {
|
||||
emit(state.copyWith(
|
||||
runningStatusModel: newStatus,
|
||||
voltage:int.tryParse(newStatus.voltage) ?? 0,
|
||||
battery: int.tryParse(newStatus.voltage) ?? 0,
|
||||
// 如果需要同步其他字段,在这里添加
|
||||
// controlMode: newStatus.controlMode,
|
||||
));
|
||||
|
||||
debugPrint('✅ [更新运行状态] 电压:${newStatus.voltage}V, 电量:${newStatus.battery}%');
|
||||
}
|
||||
}
|
||||
// 1. 初始化回包监听 (如 0x12 权限)
|
||||
// void _initPacketListener() {
|
||||
// _repository.responseStream.listen((packet) {
|
||||
@@ -170,7 +224,9 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
emit(state.copyWith(status: RemoteControlStatus.initial));
|
||||
}
|
||||
|
||||
void toggleLock() {}
|
||||
void toggleLock() {
|
||||
emit(state.copyWith(isLocked: !state.isLocked));
|
||||
}
|
||||
|
||||
void togglePermissionDialog(bool show) {
|
||||
emit(state.copyWith(showPermissionRequestDialog: show));
|
||||
@@ -188,6 +244,7 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
@override
|
||||
Future<void> close() {
|
||||
_timer?.cancel(); // 退出页面时务必销毁定时器
|
||||
_deviceStatusSub?.cancel(); // 🔥 确保清理订阅
|
||||
return super.close();
|
||||
}
|
||||
|
||||
@@ -268,6 +325,14 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
debugPrint(' [点火指令] ${i}');
|
||||
updateFunction(ignition: i);
|
||||
}
|
||||
// 发送障碍物识别指令
|
||||
void toggleObstacleRecognition() {
|
||||
emit(state.copyWith(obstacleRecognitionFlag: !state.obstacleRecognitionFlag));
|
||||
}
|
||||
|
||||
void toggleTopLeftExpand() {
|
||||
emit(state.copyWith(topRightIsExpanded: !state.topRightIsExpanded));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user