From fe5adc72dcd51c5b4184b25371574c12301ed3ae Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Wed, 11 Mar 2020 17:44:56 +0100 Subject: [PATCH] automatically retry message delete --- example/ios/Podfile.lock | 18 +++++++---- lib/src/full_screen_image.dart | 26 ++++++++++++++++ lib/src/message_input.dart | 28 ++++++++++++----- lib/src/message_widget.dart | 56 +++++++++++++++++++++++----------- pubspec.yaml | 1 + 5 files changed, 99 insertions(+), 30 deletions(-) create mode 100644 lib/src/full_screen_image.dart diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 07bb3fa8..b713289e 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -12,13 +12,13 @@ PODS: - keyboard_visibility (0.5.0): - Flutter - Reachability + - moor_ffi (0.0.1): + - Flutter - path_provider (0.0.1): - Flutter - path_provider_macos (0.0.1): - Flutter - Reachability (3.2) - - screen (0.0.1): - - Flutter - sqflite (0.0.1): - Flutter - FMDB (~> 2.7.2) @@ -32,6 +32,8 @@ PODS: - Flutter - video_player_web (0.0.1): - Flutter + - wakelock (0.0.1): + - Flutter DEPENDENCIES: - file_picker (from `.symlinks/plugins/file_picker/ios`) @@ -39,15 +41,16 @@ DEPENDENCIES: - flutter_plugin_android_lifecycle (from `.symlinks/plugins/flutter_plugin_android_lifecycle/ios`) - image_picker (from `.symlinks/plugins/image_picker/ios`) - keyboard_visibility (from `.symlinks/plugins/keyboard_visibility/ios`) + - moor_ffi (from `.symlinks/plugins/moor_ffi/ios`) - path_provider (from `.symlinks/plugins/path_provider/ios`) - path_provider_macos (from `.symlinks/plugins/path_provider_macos/ios`) - - screen (from `.symlinks/plugins/screen/ios`) - sqflite (from `.symlinks/plugins/sqflite/ios`) - url_launcher (from `.symlinks/plugins/url_launcher/ios`) - url_launcher_macos (from `.symlinks/plugins/url_launcher_macos/ios`) - url_launcher_web (from `.symlinks/plugins/url_launcher_web/ios`) - video_player (from `.symlinks/plugins/video_player/ios`) - video_player_web (from `.symlinks/plugins/video_player_web/ios`) + - wakelock (from `.symlinks/plugins/wakelock/ios`) SPEC REPOS: trunk: @@ -65,12 +68,12 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/image_picker/ios" keyboard_visibility: :path: ".symlinks/plugins/keyboard_visibility/ios" + moor_ffi: + :path: ".symlinks/plugins/moor_ffi/ios" path_provider: :path: ".symlinks/plugins/path_provider/ios" path_provider_macos: :path: ".symlinks/plugins/path_provider_macos/ios" - screen: - :path: ".symlinks/plugins/screen/ios" sqflite: :path: ".symlinks/plugins/sqflite/ios" url_launcher: @@ -83,6 +86,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/video_player/ios" video_player_web: :path: ".symlinks/plugins/video_player_web/ios" + wakelock: + :path: ".symlinks/plugins/wakelock/ios" SPEC CHECKSUMS: file_picker: 408623be2125b79a4539cf703be3d4b3abe5e245 @@ -91,16 +96,17 @@ SPEC CHECKSUMS: FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a image_picker: e3eacd46b94694dde7cf2705955cece853aa1a8f keyboard_visibility: 96a24de806fe6823c3ad956c01ba2ec6d056616f + moor_ffi: d66c9470c18e9cb333423bbcb493c105c6c774c6 path_provider: fb74bd0465e96b594bb3b5088ee4a4e7bb1f2a9d path_provider_macos: f760a3c5b04357c380e2fddb6f9db6f3015897e0 Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96 - screen: abd91ca7bf3426e1cc3646d27e9b2358d6bf07b0 sqflite: 4001a31ff81d210346b500c55b17f4d6c7589dd0 url_launcher: a1c0cc845906122c4784c542523d8cacbded5626 url_launcher_macos: fd7894421cd39320dce5f292fc99ea9270b2a313 url_launcher_web: e5527357f037c87560776e36436bf2b0288b965c video_player: 69c5f029fac4ffe4fc8a85ea7f7b793709661549 video_player_web: da8cadb8274ed4f8dbee8d7171b420dedd437ce7 + wakelock: bd3dcc6a8bcf53a1c0309780ff192dcee67c6ccb PODFILE CHECKSUM: 1b66dae606f75376c5f2135a8290850eeb09ae83 diff --git a/lib/src/full_screen_image.dart b/lib/src/full_screen_image.dart new file mode 100644 index 00000000..37413322 --- /dev/null +++ b/lib/src/full_screen_image.dart @@ -0,0 +1,26 @@ +import 'package:cached_network_image/cached_network_image.dart'; +import 'package:flutter/material.dart'; +import 'package:photo_view/photo_view.dart'; + +class FullScreenImage extends StatelessWidget { + final String url; + + const FullScreenImage({ + Key key, + @required this.url, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return Container( + child: PhotoView( + imageProvider: CachedNetworkImageProvider(url), + maxScale: PhotoViewComputedScale.covered, + minScale: PhotoViewComputedScale.contained, + heroAttributes: PhotoViewHeroAttributes( + tag: url, + ), + ), + ); + } +} diff --git a/lib/src/message_input.dart b/lib/src/message_input.dart index 927643f7..12024e08 100644 --- a/lib/src/message_input.dart +++ b/lib/src/message_input.dart @@ -586,14 +586,28 @@ class _MessageInputState extends State { _attachments.add(attachment); }); - final res = await channel.sendFile( - MultipartFile.fromBytes( - bytes, - filename: file.path.split('/').last, - ), - ); + String url; - attachment.url = res.file; + if (type == FileType.IMAGE) { + final res = await channel.sendImage( + MultipartFile.fromBytes( + bytes, + filename: file.path.split('/').last, + contentType: MediaType.parse('image/jpeg'), + ), + ); + url = res.file; + } else { + final res = await channel.sendFile( + MultipartFile.fromBytes( + bytes, + filename: file.path.split('/').last, + ), + ); + url = res.file; + } + + attachment.url = url; setState(() { attachment.uploaded = true; diff --git a/lib/src/message_widget.dart b/lib/src/message_widget.dart index b2cb6755..427c5419 100644 --- a/lib/src/message_widget.dart +++ b/lib/src/message_widget.dart @@ -8,6 +8,7 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:jiffy/jiffy.dart'; import 'package:stream_chat/stream_chat.dart'; +import 'package:stream_chat_flutter/src/full_screen_image.dart'; import 'package:stream_chat_flutter/src/message_input.dart'; import 'package:stream_chat_flutter/src/message_list_view.dart'; import 'package:stream_chat_flutter/src/reaction_picker.dart'; @@ -221,7 +222,7 @@ class _MessageWidgetState extends State alignment: alignment, child: Padding( padding: const EdgeInsets.symmetric( - horizontal: 16, + horizontal: 14, vertical: 14, ), child: Text( @@ -895,23 +896,44 @@ class _MessageWidgetState extends State Widget _buildImage( Attachment attachment, ) { - return CachedNetworkImage( - imageUrl: - attachment.thumbUrl ?? attachment.imageUrl ?? attachment.assetUrl, - errorWidget: (context, url, error) { - return Container( - width: 200, - height: 140, - color: Color(0xffd0021B).withAlpha(26), - child: Center( - child: Icon( - Icons.error_outline, - color: Colors.white, - ), - ), - ); + return GestureDetector( + onTap: () { + print(attachment.toJson()); + Navigator.push(context, MaterialPageRoute(builder: (_) { + return FullScreenImage( + url: attachment.imageUrl ?? + attachment.assetUrl ?? + attachment.thumbUrl, + ); + })); }, - fit: BoxFit.cover, + child: Hero( + tag: attachment.imageUrl ?? attachment.assetUrl ?? attachment.thumbUrl, + child: CachedNetworkImage( + placeholder: (_, __) { + return Container( + width: 200, + height: 140, + ); + }, + imageUrl: + attachment.thumbUrl ?? attachment.imageUrl ?? attachment.assetUrl, + errorWidget: (context, url, error) { + return Container( + width: 200, + height: 140, + color: Color(0xffd0021B).withAlpha(26), + child: Center( + child: Icon( + Icons.error_outline, + color: Colors.white, + ), + ), + ); + }, + fit: BoxFit.cover, + ), + ), ); } diff --git a/pubspec.yaml b/pubspec.yaml index cdfce517..1156b471 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,6 +9,7 @@ environment: dependencies: flutter: sdk: flutter + photo_view: ^0.9.2 rxdart: ^0.23.1 flutter_widgets: ^0.1.11 jiffy: ^3.0.0