地图组件和ECS框架完成

This commit is contained in:
2026-01-13 15:39:45 +08:00
parent 9d45d4c726
commit 566ec47a73
24 changed files with 17072 additions and 66 deletions

View File

@@ -6,6 +6,12 @@ import '../providers/chat_provider.dart';
import '../widgets/message_bubble.dart';
import '../widgets/typing_indicator.dart';
import '../widgets/chat_input.dart';
import 'map_screen.dart'; // 导入地图界面
// 定义一个 GlobalKey 来访问 _ChatScreenState
final GlobalKey<_ChatScreenState> chatScreenStateKey = GlobalKey<_ChatScreenState>();
class ChatScreen extends StatefulWidget {
const ChatScreen({super.key});
@@ -16,6 +22,13 @@ class ChatScreen extends StatefulWidget {
class _ChatScreenState extends State<ChatScreen> {
final ScrollController _scrollController = ScrollController();
bool _mapViewOpen = false; // 控制地图界面是否展开
void _toggleMapView() {
setState(() {
_mapViewOpen = !_mapViewOpen;
});
}
void _scrollToBottom() {
if (_scrollController.hasClients) {
@@ -62,18 +75,43 @@ class _ChatScreenState extends State<ChatScreen> {
context.read<ChatProvider>().clearMessages();
},
),
// 添加地图按钮
CommandBarButton(
icon: const Icon(FluentIcons.map_layers),
label: const Text('Map'),
onPressed: _toggleMapView, // 切换地图视图
),
],
),
),
content: Column(
content: Row( // 修改为Row布局实现左右分屏
children: [
Expanded(child: _buildMessageList()),
_buildInputArea(),
// 聊天界面部分使用Expanded来正确分配空间
Expanded(
flex: 1,
child: _buildChatContent(),
),
// 地图界面部分,根据状态决定是否显示
if (_mapViewOpen)
Expanded(
child: const MapUiPage(), // 使用现有的地图页面
),
],
),
);
}
// 提取聊天内容部分到单独的方法
Widget _buildChatContent() {
return Column(
children: [
Expanded(child: _buildMessageList()),
_buildInputArea(),
],
);
}
Widget _buildMessageList() {
return Consumer<ChatProvider>(
builder: (context, chatProvider, child) {
@@ -161,7 +199,7 @@ class _ChatScreenState extends State<ChatScreen> {
color: theme.accentColor,
borderRadius: BorderRadius.circular(20),
),
child: const Icon(FluentIcons.robot, color: Colors.white, size: 40),
child: Icon(FluentIcons.robot, color: Colors.white, size: 40),
),
const SizedBox(height: 24),
Text('Hello! I\'m your AI Assistant', style: theme.typography.title),
@@ -220,4 +258,4 @@ class _ChatScreenState extends State<ChatScreen> {
_scrollController.dispose();
super.dispose();
}
}
}