Files
flutterApp/lib/features/remote_control/presentation/bloc/remote_control_state.dart

146 lines
4.9 KiB
Dart
Raw Normal View History

2026-01-18 20:21:14 +08:00
import 'package:equatable/equatable.dart';
2026-06-05 19:06:21 +08:00
import 'package:maibu_satabot_v2/features/devices/domain/entities/device_entity.dart';
2026-01-21 13:27:55 +08:00
import 'package:maibu_satabot_v2/features/remote_control/data/models/running_status_model.dart';
2026-01-18 20:21:14 +08:00
import '../../domain/entities/machine_control_status_entity.dart';
enum RemoteControlStatus { initial, controlling, error }
class RemoteControlState extends Equatable {
final RemoteControlStatus status;
2026-01-21 13:27:55 +08:00
final MachineControlStatusEntity controlEntity; // 控制业务实体
2026-01-18 20:21:14 +08:00
final String? errorMessage;
2026-06-05 19:06:21 +08:00
final bool hasPermission; // 是否获得 0x12 权限
2026-01-18 20:21:14 +08:00
final bool isEmergency;
final bool isLocked;
final int ping;
final int battery; //电池量
final int voltage; //电压
2026-01-18 20:21:14 +08:00
final String permissionPlatform;
final String currentPlatform;
final bool showPermissionRequestDialog;
2026-06-05 19:06:21 +08:00
final String? requestingDeviceId; // 🔥 请求权限的设备ID
final String? requestingPlatform; // 🔥 请求权限的平台
2026-01-21 13:27:55 +08:00
final bool showLeftPip;
final bool showRightPip;
final bool topRightIsExpanded; // 顶部右侧按钮展开状态
final bool obstacleRecognitionFlag; // 障碍物识别标志位(这是UI显示的)
2026-01-21 13:27:55 +08:00
final String obstacleFlag; //障碍物标志位
2026-06-05 19:06:21 +08:00
final RunningStatusModel runningStatusModel;
final DeviceEntity? targetDevice;
2026-07-11 16:46:53 +08:00
final bool hasReceivedStatusPush; // 是否收到过设备状态推送
// 🔥 状态更新类型标记 - 用于区分是设备状态更新还是弹窗状态更新
final String? updateType;
2026-01-18 20:21:14 +08:00
const RemoteControlState({
this.status = RemoteControlStatus.initial,
required this.controlEntity,
this.errorMessage,
this.hasPermission = false,
this.isEmergency = false,
this.isLocked = false,
this.ping = 0,
this.battery = 0,
2026-01-21 13:27:55 +08:00
this.voltage = 0,
2026-01-18 20:21:14 +08:00
this.permissionPlatform = '',
this.currentPlatform = '',
this.showPermissionRequestDialog = false,
2026-06-05 19:06:21 +08:00
this.requestingDeviceId,
this.requestingPlatform,
2026-01-21 13:27:55 +08:00
this.showLeftPip = true,
this.showRightPip = true,
this.obstacleFlag = '',
required this.runningStatusModel,
2026-07-11 16:46:53 +08:00
this.hasReceivedStatusPush = false,
this.topRightIsExpanded = false,
this.obstacleRecognitionFlag = true,
2026-06-05 19:06:21 +08:00
this.targetDevice,
this.updateType,
2026-01-18 20:21:14 +08:00
});
2026-06-05 19:06:21 +08:00
// 便利 UI 更新部分属性
2026-01-18 20:21:14 +08:00
RemoteControlState copyWith({
RemoteControlStatus? status,
MachineControlStatusEntity? controlEntity,
String? errorMessage,
bool? hasPermission,
bool? isEmergency,
bool? isLocked,
int? ping,
int? battery,
2026-01-21 13:27:55 +08:00
int? voltage,
2026-01-18 20:21:14 +08:00
String? permissionPlatform,
String? currentPlatform,
bool? showPermissionRequestDialog,
2026-06-05 19:06:21 +08:00
String? requestingDeviceId,
String? requestingPlatform,
2026-01-21 13:27:55 +08:00
bool? showLeftPip,
bool? showRightPip,
RunningStatusModel? runningStatusModel,
String? obstacleFlag,
2026-07-11 16:46:53 +08:00
bool? hasReceivedStatusPush,
bool? topRightIsExpanded,
bool? obstacleRecognitionFlag,
2026-06-05 19:06:21 +08:00
DeviceEntity? targetDevice,
String? updateType,
2026-01-18 20:21:14 +08:00
}) {
return RemoteControlState(
status: status ?? this.status,
controlEntity: controlEntity ?? this.controlEntity,
errorMessage: errorMessage ?? this.errorMessage,
hasPermission: hasPermission ?? this.hasPermission,
isEmergency: isEmergency ?? this.isEmergency,
isLocked: isLocked ?? this.isLocked,
ping: ping ?? this.ping,
battery: battery ?? this.battery,
2026-01-21 13:27:55 +08:00
voltage: voltage ?? this.voltage,
2026-01-18 20:21:14 +08:00
permissionPlatform: permissionPlatform ?? this.permissionPlatform,
currentPlatform: currentPlatform ?? this.currentPlatform,
showPermissionRequestDialog:
showPermissionRequestDialog ?? this.showPermissionRequestDialog,
2026-06-05 19:06:21 +08:00
requestingDeviceId: requestingDeviceId ?? this.requestingDeviceId,
requestingPlatform: requestingPlatform ?? this.requestingPlatform,
2026-01-21 13:27:55 +08:00
showLeftPip: showLeftPip ?? this.showLeftPip,
showRightPip: showRightPip ?? this.showRightPip,
runningStatusModel: runningStatusModel ?? this.runningStatusModel,
obstacleFlag: obstacleFlag ?? this.obstacleFlag,
2026-07-11 16:46:53 +08:00
hasReceivedStatusPush: hasReceivedStatusPush ?? this.hasReceivedStatusPush,
topRightIsExpanded: topRightIsExpanded ?? this.topRightIsExpanded,
obstacleRecognitionFlag:
obstacleRecognitionFlag ?? this.obstacleRecognitionFlag,
2026-06-05 19:06:21 +08:00
targetDevice: targetDevice ?? this.targetDevice,
updateType: updateType, // 不使用 ??,因为我们想要 null 的时候就是 null
2026-01-18 20:21:14 +08:00
);
}
@override
List<Object?> get props => [
status,
controlEntity,
errorMessage,
hasPermission,
isEmergency,
isLocked,
ping,
battery,
2026-01-21 13:27:55 +08:00
voltage,
2026-01-18 20:21:14 +08:00
permissionPlatform,
currentPlatform,
showPermissionRequestDialog,
2026-06-05 19:06:21 +08:00
requestingDeviceId,
requestingPlatform,
2026-01-21 13:27:55 +08:00
showLeftPip,
showRightPip,
runningStatusModel,
obstacleFlag,
2026-07-11 16:46:53 +08:00
hasReceivedStatusPush,
topRightIsExpanded,
obstacleRecognitionFlag,
2026-06-05 19:06:21 +08:00
targetDevice,
updateType,
2026-01-18 20:21:14 +08:00
];
}