From 30082ed1763c8e576845e7ad7bee0136f3878242 Mon Sep 17 00:00:00 2001 From: lxm <1274844347@qq.com> Date: Thu, 22 May 2025 20:36:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E7=82=B9=E5=87=BB=E6=9F=A5=E7=9C=8B=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在消息气泡中点击图片时,打开全屏图片查看器。新增 `photo_view` 依赖并实现 `openImageViewer` 方法,提升用户体验。 --- .../agent/controllers/agent_controller.dart | 25 +++++++++++ lib/modules/agent/views/message_bubble.dart | 42 ++++++++++++------- pubspec.yaml | 1 + 3 files changed, 54 insertions(+), 14 deletions(-) diff --git a/lib/modules/agent/controllers/agent_controller.dart b/lib/modules/agent/controllers/agent_controller.dart index 990daad8c..b2a387879 100644 --- a/lib/modules/agent/controllers/agent_controller.dart +++ b/lib/modules/agent/controllers/agent_controller.dart @@ -15,6 +15,7 @@ import 'package:permission_handler/permission_handler.dart'; import 'package:app_settings/app_settings.dart'; import 'package:deep_voice/core/utils/logger.dart'; import 'package:path_provider/path_provider.dart'; +import 'package:photo_view/photo_view.dart'; class Message { final bool isUser; //标识信息是否来自用户还是AI @@ -959,4 +960,28 @@ class AgentController extends GetxController { void openNavigation(String start, String end, String ntype) { _navigationManager.open(start, end, ntype); } + + // 打开图片查看器 + void openImageViewer(BuildContext context, String imagePath) { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => Scaffold( + appBar: AppBar( + backgroundColor: Colors.black, + iconTheme: IconThemeData(color: Colors.white), + ), + body: Container( + color: Colors.black, + child: PhotoView( + imageProvider: FileImage(File(imagePath)), + minScale: PhotoViewComputedScale.contained, + maxScale: PhotoViewComputedScale.covered * 2, + backgroundDecoration: BoxDecoration(color: Colors.black), + ), + ), + ), + ), + ); + } } diff --git a/lib/modules/agent/views/message_bubble.dart b/lib/modules/agent/views/message_bubble.dart index 14964195b..94bbb5415 100644 --- a/lib/modules/agent/views/message_bubble.dart +++ b/lib/modules/agent/views/message_bubble.dart @@ -215,13 +215,20 @@ class MessageBubble extends GetView { if (message == '[图片]') { return Container( padding: const EdgeInsets.all(8), - child: ClipRRect( - borderRadius: BorderRadius.circular(12), - child: Image.file( - File(imagePath!), - width: 200, - height: 200, - fit: BoxFit.cover, + child: GestureDetector( + onTap: () { + // 点击图片时打开图片查看器 + Get.find() + .openImageViewer(context, imagePath ?? ''); + }, + child: ClipRRect( + borderRadius: BorderRadius.circular(12), + child: Image.file( + File(imagePath!), + width: 200, + height: 200, + fit: BoxFit.cover, + ), ), ), ); @@ -241,13 +248,20 @@ class MessageBubble extends GetView { ), ), const SizedBox(height: 8), - ClipRRect( - borderRadius: BorderRadius.circular(12), - child: Image.file( - File(imagePath!), - width: 200, - height: 200, - fit: BoxFit.cover, + GestureDetector( + onTap: () { + // 点击图片时打开图片查看器 + Get.find() + .openImageViewer(context, imagePath ?? ''); + }, + child: ClipRRect( + borderRadius: BorderRadius.circular(12), + child: Image.file( + File(imagePath!), + width: 200, + height: 200, + fit: BoxFit.cover, + ), ), ), ], diff --git a/pubspec.yaml b/pubspec.yaml index 94783cbd4..fd7ad853a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -37,6 +37,7 @@ dependencies: file_picker: ^10.1.5 haptic_feedback: ^0.5.1+1 tencentcloud_cos_sdk_plugin: ^1.2.3 + photo_view: ^0.15.0 window_size: git: