From 52f7a7a2099fb987a7ee23c9d0729dc54d6cb756 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Fri, 28 Feb 2020 17:14:53 +0100 Subject: [PATCH] add loading upload --- lib/src/message_input.dart | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/lib/src/message_input.dart b/lib/src/message_input.dart index 8f3ca608..c0d6a7d7 100644 --- a/lib/src/message_input.dart +++ b/lib/src/message_input.dart @@ -168,6 +168,16 @@ class _MessageInputState extends State { ), ), ), + attachment.uploaded + ? SizedBox() + : Positioned.fill( + child: Center( + child: Padding( + padding: const EdgeInsets.all(16.0), + child: CircularProgressIndicator(), + ), + ), + ), ], ), ), @@ -180,7 +190,10 @@ class _MessageInputState extends State { Widget _buildAttachment(_SendingAttachment attachment) { switch (attachment.type) { case FileType.IMAGE: - return Image.file(attachment.file); + return Image.file( + attachment.file, + fit: BoxFit.cover, + ); break; case FileType.VIDEO: return Container( @@ -294,6 +307,16 @@ class _MessageInputState extends State { final channel = StreamChannel.of(context).channel; final bytes = await file.readAsBytes(); + + final attachment = _SendingAttachment( + file: file, + type: type, + ); + + setState(() { + _attachments.add(attachment); + }); + final res = await channel.sendFile( MultipartFile.fromBytes( bytes, @@ -302,11 +325,7 @@ class _MessageInputState extends State { ); setState(() { - _attachments.add(_SendingAttachment( - url: res.file, - file: file, - type: type, - )); + attachment.uploaded = true; }); } @@ -388,6 +407,7 @@ class _SendingAttachment { final String url; final File file; final FileType type; + bool uploaded = false; _SendingAttachment({ this.url,