Files
ai_chat_assistant/lib/models/vehicle_cmd.dart
Chen Li 130755f9e1 0812
2025-08-12 13:36:42 +08:00

37 lines
1.1 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)';
}
}