Merge pull request #289 from GetStream/hotfix/attachmentUpload
default to success and hide indicators if not needed
This commit is contained in:
@@ -58,7 +58,7 @@ class Attachment {
|
|||||||
final AttachmentFile file;
|
final AttachmentFile file;
|
||||||
|
|
||||||
/// The current upload state of the attachment
|
/// The current upload state of the attachment
|
||||||
final UploadState uploadState;
|
UploadState uploadState;
|
||||||
|
|
||||||
/// Map of custom channel extraData
|
/// Map of custom channel extraData
|
||||||
@JsonKey(includeIfNull: false)
|
@JsonKey(includeIfNull: false)
|
||||||
@@ -123,10 +123,15 @@ class Attachment {
|
|||||||
this.actions,
|
this.actions,
|
||||||
this.extraData,
|
this.extraData,
|
||||||
this.file,
|
this.file,
|
||||||
this.uploadState,
|
UploadState uploadState,
|
||||||
}) : id = id ?? Uuid().v4(),
|
}) : id = id ?? Uuid().v4(),
|
||||||
title = title ?? file?.name,
|
title = title ?? file?.name,
|
||||||
localUri = file?.path != null ? Uri.parse(file.path) : null;
|
localUri = file?.path != null ? Uri.parse(file.path) : null {
|
||||||
|
this.uploadState = uploadState ??
|
||||||
|
((assetUrl != null || imageUrl != null)
|
||||||
|
? UploadState.success()
|
||||||
|
: UploadState.preparing());
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a new instance from a json
|
/// Create a new instance from a json
|
||||||
factory Attachment.fromJson(Map<String, dynamic> json) {
|
factory Attachment.fromJson(Map<String, dynamic> json) {
|
||||||
|
|||||||
+3
-1
@@ -27,7 +27,9 @@ class AttachmentUploadStateBuilder extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (attachment.uploadState == null) return Offstage();
|
if (message.status == null || message.status == MessageSendingStatus.sent) {
|
||||||
|
return Offstage();
|
||||||
|
}
|
||||||
|
|
||||||
final messageId = message.id;
|
final messageId = message.id;
|
||||||
final attachmentId = attachment.id;
|
final attachmentId = attachment.id;
|
||||||
|
|||||||
@@ -227,6 +227,20 @@ class FileAttachment extends AttachmentWidget {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (message != null &&
|
||||||
|
(message.status == null ||
|
||||||
|
message.status == MessageSendingStatus.sent)) {
|
||||||
|
trailingWidget = IconButton(
|
||||||
|
icon: StreamSvgIcon.cloudDownload(color: theme.colorTheme.black),
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
visualDensity: VisualDensity.compact,
|
||||||
|
splashRadius: 16,
|
||||||
|
onPressed: () {
|
||||||
|
launchURL(context, attachment.assetUrl);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return Material(
|
return Material(
|
||||||
type: MaterialType.transparency,
|
type: MaterialType.transparency,
|
||||||
child: trailingWidget,
|
child: trailingWidget,
|
||||||
@@ -241,6 +255,9 @@ class FileAttachment extends AttachmentWidget {
|
|||||||
);
|
);
|
||||||
return attachment.uploadState?.when(
|
return attachment.uploadState?.when(
|
||||||
preparing: () {
|
preparing: () {
|
||||||
|
if (message == null) {
|
||||||
|
return Text('${fileSize(size, 2)}', style: textStyle);
|
||||||
|
}
|
||||||
return UploadProgressIndicator(
|
return UploadProgressIndicator(
|
||||||
uploaded: 0,
|
uploaded: 0,
|
||||||
total: double.maxFinite.toInt(),
|
total: double.maxFinite.toInt(),
|
||||||
|
|||||||
@@ -109,10 +109,7 @@ class ImageActionsModal extends StatelessWidget {
|
|||||||
final remainingAttachments = [...message.attachments]
|
final remainingAttachments = [...message.attachments]
|
||||||
..removeAt(currentIndex);
|
..removeAt(currentIndex);
|
||||||
channel.updateMessage(message.copyWith(
|
channel.updateMessage(message.copyWith(
|
||||||
attachments: remainingAttachments.map((e) {
|
attachments: remainingAttachments,
|
||||||
return e.copyWith(
|
|
||||||
uploadState: UploadState.success());
|
|
||||||
}).toList(),
|
|
||||||
));
|
));
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
|
|||||||
Reference in New Issue
Block a user