Files
ai_chat_assistant/example/README.md
2025-09-23 10:58:47 +08:00

93 lines
2.1 KiB
Markdown
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.

# AI Chat Assistant Example
这是 AI Chat Assistant Flutter 插件的示例应用,展示了如何集成和使用 AI 聊天助手功能。
## 🚀 快速开始
### 1. 安装依赖
```bash
cd example
flutter pub get
```
### 2. 运行应用
```bash
flutter run
```
## 📱 示例功能
### 车控命令处理器示例
本示例展示了如何实现自定义的车控命令处理器:
```dart
class VehicleCommandClent extends VehicleCommandHandler {
@override
Future<(bool, Map<String, dynamic>?)> executeCommand(VehicleCommand command) async {
// 在这里实现具体的车控命令执行逻辑
print('执行车控命令: ${command.type}, 参数: ${command.params}');
// 更新命令状态为执行中
commandCubit?.emit(AIChatCommandState(
commandId: command.commandId,
commandType: command.type,
params: command.params,
status: AIChatCommandStatus.executing,
timestamp: DateTime.now(),
));
// 模拟命令执行
await Future.delayed(const Duration(seconds: 2));
// 更新命令状态为成功
commandCubit?.emit(AIChatCommandState(
commandId: command.commandId,
commandType: command.type,
params: command.params,
status: AIChatCommandStatus.success,
timestamp: DateTime.now(),
result: {'message': '命令执行成功'},
));
return (true, {'message': '命令已执行'});
}
}
```
### 初始化示例
```dart
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// 请求麦克风权限
if (!await Permission.microphone.isGranted) {
await Permission.microphone.request();
}
// 初始化 AI Chat Assistant注册车控命令处理器
AIChatAssistantManager.instance.setupCommandHandle(
commandHandler: VehicleCommandClent()
);
runApp(const MyApp());
}
```
## 🎯 示例特性
- ✅ 完整的车控命令处理示例
- ✅ 权限管理示例
- ✅ 状态管理集成
- ✅ AI 聊天界面集成
- ✅ 语音识别功能
- ✅ TTS 语音播报
## 📖 了解更多
- 查看主项目 [README](../README.md) 了解完整的功能特性
- 查看 [API 文档](../README.md#-api-文档) 了解接口使用方法