feat: 修复了插件需要外部Provider的问题;加上了一个简易的车控状态返回
This commit is contained in:
52
lib/manager.dart
Normal file
52
lib/manager.dart
Normal file
@@ -0,0 +1,52 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'bloc/ai_chat_cubit.dart';
|
||||
import 'bloc/command_state.dart';
|
||||
import 'models/vehicle_cmd.dart';
|
||||
|
||||
/// 车辆命令处理器抽象类
|
||||
abstract class VehicleCommandHandler {
|
||||
AIChatCommandCubit? commandCubit;
|
||||
/// 执行车辆控制命令
|
||||
Future<(bool, Map<String, dynamic>?)> executeCommand(VehicleCommand command);
|
||||
}
|
||||
|
||||
class AIChatAssistantManager {
|
||||
static final AIChatAssistantManager _instance = AIChatAssistantManager._internal();
|
||||
|
||||
static AIChatAssistantManager get instance => _instance;
|
||||
|
||||
AIChatAssistantManager._internal() {
|
||||
// 初始化代码
|
||||
debugPrint('AIChatAssistant 单例创建');
|
||||
_commandCubit = AIChatCommandCubit();
|
||||
}
|
||||
|
||||
AIChatCommandCubit? _commandCubit;
|
||||
|
||||
VehicleCommandHandler? commandClient;
|
||||
|
||||
/// 初始化命令处理器
|
||||
void setupCommandHandle({
|
||||
required VehicleCommandHandler commandHandler,
|
||||
}) {
|
||||
commandClient = commandHandler;
|
||||
commandClient?.commandCubit = _commandCubit;
|
||||
}
|
||||
|
||||
/// 获取命令状态流
|
||||
Stream<AIChatCommandState> get commandStateStream {
|
||||
if (_commandCubit == null) {
|
||||
throw StateError('AIChatAssistant 未初始化');
|
||||
}
|
||||
return _commandCubit!.stream;
|
||||
}
|
||||
|
||||
/// 释放资源
|
||||
void dispose() {
|
||||
_commandCubit?.close();
|
||||
_commandCubit = null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user