feat: 修复了插件需要外部Provider的问题;加上了一个简易的车控状态返回
This commit is contained in:
@@ -1,9 +1,48 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:ai_chat_assistant/app.dart';
|
||||
import 'package:ai_chat_assistant/services/message_service.dart';
|
||||
import 'package:ai_chat_assistant/enums/vehicle_command_type.dart';
|
||||
import 'package:ai_chat_assistant/ai_chat_assistant.dart';
|
||||
|
||||
class VehicleCommandClent extends VehicleCommandHandler {
|
||||
@override
|
||||
AIChatCommandCubit? get commandCubit => super.commandCubit;
|
||||
|
||||
@override
|
||||
Future<(bool, Map<String, dynamic>?)> executeCommand(VehicleCommand command) async {
|
||||
// 在这里实现具体的车控命令执行逻辑
|
||||
print('执行车控命令: ${command.type}, 参数: ${command.params}');
|
||||
|
||||
if (commandCubit != null) {
|
||||
|
||||
commandCubit?.emit(AIChatCommandState(
|
||||
commandId: command.commandId,
|
||||
commandType: command.type,
|
||||
params: command.params,
|
||||
status: AIChatCommandStatus.executing,
|
||||
timestamp: DateTime.now(),
|
||||
errorMessage: null,
|
||||
result: null,
|
||||
));
|
||||
}
|
||||
|
||||
// 模拟命令执行完成
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
|
||||
if (commandCubit != null) {
|
||||
commandCubit?.emit(AIChatCommandState(
|
||||
commandId: command.commandId,
|
||||
commandType: command.type,
|
||||
params: command.params,
|
||||
status: AIChatCommandStatus.success,
|
||||
timestamp: DateTime.now(),
|
||||
errorMessage: null,
|
||||
result: {'message': '命令执行成功'},
|
||||
));
|
||||
}
|
||||
|
||||
return Future.value((true, {'message': '命令已执行'}));
|
||||
}
|
||||
}
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
@@ -14,20 +53,17 @@ void main() async {
|
||||
}
|
||||
|
||||
// 初始化 AI Chat Assistant,注册车控命令回调
|
||||
ChatAssistantApp.initialize(
|
||||
commandCallback: (VehicleCommandType type, Map<String, dynamic>? params) async {
|
||||
// 这里是示例的车控命令处理逻辑
|
||||
print('收到车控命令: $type, 参数: $params');
|
||||
return Future.value((true, {'message': '命令已执行'}));
|
||||
},
|
||||
);
|
||||
// ChatAssistantApp.initialize(
|
||||
// commandCallback: (VehicleCommandType type, Map<String, dynamic>? params) async {
|
||||
// // 这里是示例的车控命令处理逻辑
|
||||
// print('收到车控命令: $type, 参数: $params');
|
||||
// return Future.value((true, {'message': '命令已执行'}));
|
||||
// },
|
||||
// );
|
||||
|
||||
runApp(
|
||||
ChangeNotifierProvider(
|
||||
create: (_) => MessageService(),
|
||||
child: const MyApp(),
|
||||
),
|
||||
);
|
||||
AIChatAssistantManager.instance.setupCommandHandle(commandHandler: VehicleCommandClent());
|
||||
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
|
||||
Reference in New Issue
Block a user