From 3544e5ab3ecd539a0d80ee94ea2bd1fe00980e88 Mon Sep 17 00:00:00 2001 From: Linloir <3145078758@qq.com> Date: Sun, 23 Oct 2022 11:36:49 +0800 Subject: [PATCH] Feature: - Image Viewer --- lib/chat/view/common/image_box.dart | 53 +++++++++++++++++++++++++---- lib/main.dart | 4 +-- pubspec.lock | 14 ++++---- pubspec.yaml | 3 +- 4 files changed, 57 insertions(+), 17 deletions(-) diff --git a/lib/chat/view/common/image_box.dart b/lib/chat/view/common/image_box.dart index 65c805d..a73a6b3 100644 --- a/lib/chat/view/common/image_box.dart +++ b/lib/chat/view/common/image_box.dart @@ -1,18 +1,15 @@ /* * @Author : Linloir * @Date : 2022-10-14 17:04:20 - * @LastEditTime : 2022-10-23 10:52:45 + * @LastEditTime : 2022-10-23 11:35:10 * @Description : */ import 'dart:convert'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:shared_preferences/shared_preferences.dart'; -import 'package:tcp_client/chat/cubit/chat_cubit.dart'; +import 'package:photo_view/photo_view.dart'; import 'package:tcp_client/chat/model/chat_history.dart'; -import 'package:tcp_client/repositories/tcp_repository/models/tcp_request.dart'; class ImageBox extends StatelessWidget { const ImageBox({ @@ -30,13 +27,55 @@ class ImageBox extends StatelessWidget { children: [ Container( constraints: const BoxConstraints(maxWidth: 200, maxHeight: 150), - child: history.preCachedImage ?? Image.memory(base64Decode(history.message.contentDecoded)), + child: Hero( + tag: history.message.contentmd5, + child: history.preCachedImage ?? Image.memory(base64Decode(history.message.contentDecoded)), + ), ), Material( color: Colors.transparent, child: InkWell( splashColor: Colors.white.withOpacity(0.1), - onTap: (){}, + onTap: (){ + var image = history.preCachedImage?.image ?? Image.memory(base64.decode(history.message.contentDecoded)).image; + Navigator.of(context).push(MaterialPageRoute( + builder:(context) { + return Scaffold( + body: Stack( + children: [ + Positioned.fill( + child: PhotoView( + heroAttributes: PhotoViewHeroAttributes( + tag: history.message.contentmd5 + ), + imageProvider: image, + minScale: PhotoViewComputedScale.contained, + ) + ), + Positioned.fill( + child: SafeArea( + child: Align( + alignment: Alignment.topRight, + child: IconButton( + icon: Icon( + Icons.close_rounded, + shadows: [ + Shadow(blurRadius: 8.0, color: Colors.white.withOpacity(0.5)) + ], + ), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ), + ), + ), + ], + ), + ); + }, + )); + }, ) ), ] diff --git a/lib/main.dart b/lib/main.dart index 0acc010..8972f9d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,7 +1,7 @@ /* * @Author : Linloir * @Date : 2022-10-10 08:04:53 - * @LastEditTime : 2022-10-23 10:44:13 + * @LastEditTime : 2022-10-23 11:36:04 * @Description : */ import 'package:flutter/gestures.dart'; @@ -49,7 +49,7 @@ class SplashPage extends StatelessWidget { return BlocProvider( create: (context) { return InitializationCubit( - serverAddress: 'chat.linloir.cn', + serverAddress: '127.0.0.1', serverPort: 20706 ); }, diff --git a/pubspec.lock b/pubspec.lock index 29f91e3..a84ea90 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -78,13 +78,6 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.0.2+1" - easy_image_viewer: - dependency: "direct main" - description: - name: easy_image_viewer - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.1.0" equatable: dependency: "direct main" description: @@ -291,6 +284,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.1.3" + photo_view: + dependency: "direct main" + description: + name: photo_view + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.14.0" platform: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 9acf638..75dd8fc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -57,7 +57,8 @@ dependencies: easy_debounce: ^2.0.2+1 path: ^1.8.2 window_manager: ^0.2.7 - easy_image_viewer: ^1.1.0 + # easy_image_viewer: ^1.1.0 + photo_view: ^0.14.0 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons.