add loading upload

This commit is contained in:
Salvatore Giordano
2020-02-28 17:14:53 +01:00
parent b6f0b6f2c1
commit 52f7a7a209
+26 -6
View File
@@ -168,6 +168,16 @@ class _MessageInputState extends State<MessageInput> {
), ),
), ),
), ),
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<MessageInput> {
Widget _buildAttachment(_SendingAttachment attachment) { Widget _buildAttachment(_SendingAttachment attachment) {
switch (attachment.type) { switch (attachment.type) {
case FileType.IMAGE: case FileType.IMAGE:
return Image.file(attachment.file); return Image.file(
attachment.file,
fit: BoxFit.cover,
);
break; break;
case FileType.VIDEO: case FileType.VIDEO:
return Container( return Container(
@@ -294,6 +307,16 @@ class _MessageInputState extends State<MessageInput> {
final channel = StreamChannel.of(context).channel; final channel = StreamChannel.of(context).channel;
final bytes = await file.readAsBytes(); final bytes = await file.readAsBytes();
final attachment = _SendingAttachment(
file: file,
type: type,
);
setState(() {
_attachments.add(attachment);
});
final res = await channel.sendFile( final res = await channel.sendFile(
MultipartFile.fromBytes( MultipartFile.fromBytes(
bytes, bytes,
@@ -302,11 +325,7 @@ class _MessageInputState extends State<MessageInput> {
); );
setState(() { setState(() {
_attachments.add(_SendingAttachment( attachment.uploaded = true;
url: res.file,
file: file,
type: type,
));
}); });
} }
@@ -388,6 +407,7 @@ class _SendingAttachment {
final String url; final String url;
final File file; final File file;
final FileType type; final FileType type;
bool uploaded = false;
_SendingAttachment({ _SendingAttachment({
this.url, this.url,