This commit is contained in:
Chen Li
2025-08-12 13:36:42 +08:00
parent 8191bef32e
commit 130755f9e1
47 changed files with 3728 additions and 761 deletions

View File

@@ -0,0 +1,36 @@
import '../enums/vehicle_command_type.dart';
class VehicleCommand {
final VehicleCommandType type;
final Map<String, dynamic>? params;
final String error;
VehicleCommand({required this.type, this.params, this.error = ''});
// 从字符串创建命令用于从API响应解析
factory VehicleCommand.fromString(
String commandStr, Map<String, dynamic>? params, String error) {
// 将字符串转换为枚举值
VehicleCommandType type;
try {
type = VehicleCommandType.values.firstWhere(
(e) => e.name == commandStr,
orElse: () => VehicleCommandType.unknown,
);
} catch (e) {
print('Error parsing command string: $e');
// 默认为搜车指令,或者你可以选择抛出异常
type = VehicleCommandType.unknown;
}
return VehicleCommand(type: type, params: params, error: error);
}
// 将命令转换为字符串用于API请求
String get commandString => type.name;
@override
String toString() {
return 'VehicleCommand(command: ${type.name}, params: $params)';
}
}