From 60e1af4a33249450452068a489403fb86091581a Mon Sep 17 00:00:00 2001 From: lxm <1274844347@qq.com> Date: Wed, 18 Jun 2025 15:49:28 +0800 Subject: [PATCH] =?UTF-8?q?refactor(agent=5Fview):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=B6=88=E6=81=AF=E7=9A=84=E5=A4=8D=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/modules/agent/views/agent_view.dart | 249 +++++------------------- 1 file changed, 44 insertions(+), 205 deletions(-) diff --git a/lib/modules/agent/views/agent_view.dart b/lib/modules/agent/views/agent_view.dart index b07c4efff..fb1887ee5 100644 --- a/lib/modules/agent/views/agent_view.dart +++ b/lib/modules/agent/views/agent_view.dart @@ -168,34 +168,22 @@ class AgentView extends StatelessWidget { final message = controller .messages[controller.messages.length - 1 - index]; return Padding( - padding: const EdgeInsets.only(bottom: 8), - child: !message.isUser - ? GestureDetector( - onLongPressStart: - (LongPressStartDetails details) { - _onLongPressMessageContent( - context, isDarkMode, details, message); - }, - child: MessageBubble( - isUser: message.isUser, - message: message.text, - timestamp: message.timestamp, - isRecognizing: message.isRecognizing, - hasImage: message.hasImage, - imagePath: message.imagePath, - meta: message.meta, - ), - ) - : MessageBubble( - isUser: message.isUser, - message: message.text, - timestamp: message.timestamp, - isRecognizing: message.isRecognizing, - hasImage: message.hasImage, - imagePath: message.imagePath, - meta: message.meta, - ), - ); + padding: const EdgeInsets.only(bottom: 8), + child: GestureDetector( + onLongPressStart: (LongPressStartDetails details) { + _onLongPressMessageContent( + context, isDarkMode, details, message); + }, + child: MessageBubble( + isUser: message.isUser, + message: message.text, + timestamp: message.timestamp, + isRecognizing: message.isRecognizing, + hasImage: message.hasImage, + imagePath: message.imagePath, + meta: message.meta, + ), + )); }, ), ), @@ -602,164 +590,36 @@ class AgentView extends StatelessWidget { )); }, ), - // 自定义分隔线样式 - PopupMenuItem( - height: 1, // 控制间距 - enabled: false, - child: Divider( - height: 1, - thickness: 0.8, - indent: 0, - endIndent: 0, - color: isDarkMode ? Colors.grey[700] : Colors.grey[300], + if (!message.isUser) ...[ + // 自定义分隔线样式 + PopupMenuItem( + height: 1, // 控制间距 + enabled: false, + child: Divider( + height: 1, + thickness: 0.8, + indent: 0, + endIndent: 0, + color: isDarkMode ? Colors.grey[700] : Colors.grey[300], + ), ), - ), - _popupMenuEntry( - Icon( - Icons.report, - size: 20.w, - color: isDarkMode ? Colors.red[700] : Colors.red, + _popupMenuEntry( + Icon( + Icons.report, + size: 20.w, + color: isDarkMode ? Colors.red[700] : Colors.red, + ), + '举报'.tr, // 举报 + isDarkMode ? Colors.red[700]! : Colors.red, + () { + // 实现举报功能 + final reportController = Get.find(); + reportController.initReport(message); + + _showReportForm(context, isDarkMode); + }, ), - '举报'.tr, // 举报 - isDarkMode ? Colors.red[700]! : Colors.red, - () { - // 实现举报功能 - final reportController = Get.find(); - reportController.initReport(message); - - _showReportForm(context, isDarkMode); - // showModalBottomSheet( - // context: context, - // isScrollControlled: true, // 关键:允许弹窗随键盘移动 - // backgroundColor: - // isDarkMode ? AppColors.cardBackground : Colors.white, - // shape: RoundedRectangleBorder( - // borderRadius: BorderRadius.vertical(top: Radius.circular(16.r)), - // ), - // builder: (BuildContext context) { - // return Padding( - // // 添加底部内边距以容纳键盘 - // padding: EdgeInsets.only( - // bottom: MediaQuery.of(context).viewInsets.bottom, - // ), - // child: Container( - // padding: EdgeInsets.all(16.w), - // child: SingleChildScrollView( - // // 添加滚动视图 - // child: Column( - // mainAxisSize: MainAxisSize.min, - // crossAxisAlignment: CrossAxisAlignment.stretch, - // children: [ - // Stack( - // alignment: Alignment.center, - // children: [ - // Center( - // child: Text( - // '举报', - // style: TextStyle( - // fontSize: 18.sp, - // fontWeight: FontWeight.bold, - // color: isDarkMode - // ? Colors.white - // : Colors.black, - // ), - // ), - // ), - // SizedBox( - // height: 20.w, - // ), - // Positioned( - // right: 0, - // child: IconButton( - // icon: Icon( - // Icons.close, - // color: isDarkMode - // ? Colors.grey[400] - // : Colors.black54, - // ), - // onPressed: () => Navigator.pop(context), - // ), - // ), - // ], - // ), - // Container( - // padding: EdgeInsets.symmetric(horizontal: 12.w), - // margin: EdgeInsets.only(bottom: 10.w), - // child: Divider( - // height: 1, - // color: Colors.grey[300], - // ), - // ), - // Wrap( - // spacing: 8.w, - // runSpacing: 8.h, - // children: [ - // _buildReportChip('有害/不安全', isDarkMode), - // _buildReportChip('色情低俗', isDarkMode), - // _buildReportChip('误导攻击', isDarkMode), - // _buildReportChip('违法犯罪', isDarkMode), - // _buildReportChip('隐私相关', isDarkMode), - // _buildReportChip('侵犯我的著作权、名誉权等', isDarkMode), - // _buildReportChip('其他', isDarkMode), - // ], - // ), - // SizedBox(height: 16.h), - // Container( - // padding: EdgeInsets.all(12.w), - // decoration: BoxDecoration( - // color: isDarkMode - // ? Colors.grey[800] - // : Colors.grey[200], - // borderRadius: BorderRadius.circular(8.r), - // ), - // child: TextField( - // maxLines: 3, - // style: TextStyle( - // color: isDarkMode ? Colors.white : Colors.black, - // ), - // decoration: InputDecoration( - // hintText: '我们想知道你举报的原因,你可以描述你遇到的问题。', - // hintStyle: TextStyle( - // color: isDarkMode - // ? Colors.white70 - // : Colors.black54, - // fontSize: 14.sp, - // ), - // border: InputBorder.none, - // ), - // ), - // ), - // SizedBox(height: 14.h), - // ElevatedButton( - // style: ElevatedButton.styleFrom( - // backgroundColor: Colors.blue, - // foregroundColor: Colors.white, - // padding: EdgeInsets.symmetric(vertical: 12.h), - // shape: RoundedRectangleBorder( - // borderRadius: BorderRadius.circular(8.r), - // ), - // ), - // child: Text('提交'), - // onPressed: () { - // Navigator.pop(context); - // Get.snackbar( - // '提示', - // '举报已提交,我们会尽快处理', - // backgroundColor: Colors.green.withOpacity(0.8), - // colorText: Colors.white, - // ); - // }, - // ), - // SizedBox(height: 8.h), - // ], - // ), - // ), - // ), - // ); - // }, - // ); - }, - ), + ] ], ); } @@ -784,27 +644,6 @@ class AgentView extends StatelessWidget { ); } - // // 添加这个辅助方法来创建举报选项 - // Widget _buildReportChip(String label, bool isDarkMode) { - // return ChoiceChip( - // label: Text( - // label, - // style: TextStyle( - // color: isDarkMode ? Colors.white : Colors.black87, - // fontSize: 14.sp, - // ), - // ), - // selected: false, - // backgroundColor: isDarkMode ? Colors.grey[800] : Colors.grey[200], - // shape: RoundedRectangleBorder( - // borderRadius: BorderRadius.circular(16.r), - // ), - // onSelected: (bool selected) { - // // 可以在这里处理选择逻辑 - // }, - // ); - // } - PopupMenuEntry _popupMenuEntry( Icon icon, String title,