add loading upload
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user