2025-09-10 15:35:07 +08:00
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
|
|
import 'package:provider/provider.dart';
|
2025-09-18 15:53:39 +08:00
|
|
|
|
import 'package:ai_chat_assistant/ai_chat_assistant.dart';
|
|
|
|
|
|
|
2025-09-26 16:23:48 +08:00
|
|
|
|
import 'pages/home.dart';
|
|
|
|
|
|
|
2025-09-18 15:53:39 +08:00
|
|
|
|
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': '命令已执行'}));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-10 15:35:07 +08:00
|
|
|
|
|
|
|
|
|
|
void main() async {
|
|
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
|
|
|
|
|
|
|
// 请求麦克风权限
|
|
|
|
|
|
if (!await Permission.microphone.isGranted) {
|
|
|
|
|
|
await Permission.microphone.request();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化 AI Chat Assistant,注册车控命令回调
|
2025-09-18 15:53:39 +08:00
|
|
|
|
// ChatAssistantApp.initialize(
|
|
|
|
|
|
// commandCallback: (VehicleCommandType type, Map<String, dynamic>? params) async {
|
|
|
|
|
|
// // 这里是示例的车控命令处理逻辑
|
|
|
|
|
|
// print('收到车控命令: $type, 参数: $params');
|
|
|
|
|
|
// return Future.value((true, {'message': '命令已执行'}));
|
|
|
|
|
|
// },
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
|
|
AIChatAssistantManager.instance.setupCommandHandle(commandHandler: VehicleCommandClent());
|
|
|
|
|
|
|
|
|
|
|
|
runApp(const MyApp());
|
2025-09-26 16:23:48 +08:00
|
|
|
|
|
|
|
|
|
|
AIChatAssistantManager.instance.setWakeWordDetection(true);
|
2025-09-10 15:35:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
|
|
const MyApp({super.key});
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
return MaterialApp(
|
|
|
|
|
|
title: 'AI Chat Assistant Example',
|
|
|
|
|
|
theme: ThemeData(
|
|
|
|
|
|
primarySwatch: Colors.blue,
|
|
|
|
|
|
useMaterial3: true,
|
|
|
|
|
|
),
|
2025-09-26 16:23:48 +08:00
|
|
|
|
home: HomePage(),
|
2025-09-10 15:35:07 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|