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: