import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import '../controllers/explore_controller.dart'; import '../../chat/controllers/chat_controller.dart'; import '../../chat/views/chat_view.dart'; import '../../../data/providers/agent_provider.dart'; import '../../../core/widgets/common_bottom_nav.dart'; import '../../../core/routes/app_routes.dart'; class ExploreView extends GetView { const ExploreView({Key? key}) : super(key: key); void _onChatItemTap(ChatItem item) { // 获取对应的Agent final agent = AgentProvider.getAgentById(item.id); if (agent == null) { Get.snackbar( 'Error', 'Agent not found', snackPosition: SnackPosition.BOTTOM, ); return; } // 检查是否是同声翻译官 if (agent.id == 'simultaneous_interpreter') { // 导航到翻译页面 Get.toNamed(Routes.translation); return; } // 导航到聊天页面,让 binding 来处理控制器的创建 Get.toNamed('/chat', arguments: { 'agentId': agent.id, 'agentName': agent.name, 'agentAvatar': agent.avatarUrl, 'agentSubtitle': agent.description, 'systemPrompt': agent.systemPrompt, 'welcomeMessage': agent.welcomeMessage, 'playVoiceOnEnter': false, }); } Widget _buildChatItem(ChatItem item) { // 获取对应的Agent final agent = AgentProvider.getAgentById(item.id); if (agent == null) return const SizedBox.shrink(); return InkWell( onTap: () => _onChatItemTap(item), child: Container( padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.h), child: Row( children: [ // 头像 CircleAvatar( radius: 25.r, backgroundImage: AssetImage(agent.avatarUrl), backgroundColor: const Color(0xFFEEF4FF), ), SizedBox(width: 12.w), // 聊天内容 Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ // 名称行 Row( children: [ Text( agent.name, style: TextStyle( fontSize: 16.sp, fontWeight: FontWeight.w600, color: Colors.black, ), ), if (agent.tag == '推荐') ...[ SizedBox(width: 8.w), Container( padding: EdgeInsets.symmetric(horizontal: 6.w, vertical: 2.h), decoration: BoxDecoration( color: const Color(0xFFE8F5E9), borderRadius: BorderRadius.circular(4.r), ), child: Text( '推荐', style: TextStyle( fontSize: 12.sp, color: const Color(0xFF4CAF50), ), ), ), ], ], ), SizedBox(height: 4.h), // 描述 Text( agent.description, style: TextStyle( fontSize: 14.sp, color: Colors.grey[600], ), maxLines: 1, overflow: TextOverflow.ellipsis, ), ], ), ), ], ), ), ); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, appBar: AppBar( backgroundColor: Colors.white, elevation: 0, title: Text( '对话', style: TextStyle( fontSize: 17.sp, fontWeight: FontWeight.w600, color: Colors.black, ), ), centerTitle: true, actions: [ IconButton( icon: Icon( Icons.search, color: Colors.black, size: 24.sp, ), onPressed: () {}, ), IconButton( icon: Icon( Icons.add_circle_outline, color: Colors.black, size: 24.sp, ), onPressed: () {}, ), SizedBox(width: 4.w), ], ), body: Obx(() => ListView.separated( itemCount: controller.chatList.length, separatorBuilder: (context, index) => Divider( height: 1, indent: 16.w, endIndent: 16.w, color: const Color(0xFFEEEEEE), ), itemBuilder: (context, index) => _buildChatItem(controller.chatList[index]), )), bottomNavigationBar: const CommonBottomNav(currentIndex: 1), ); } }