TF-2118 Handle drop n drop file as attachment

(cherry picked from commit cb1f15dcba46a15dbd5c5a8493593854855be331)
This commit is contained in:
dab246
2023-09-28 11:12:34 +07:00
committed by Dat H. Pham
parent 25b26acc42
commit 8b20e9e1d4
6 changed files with 105 additions and 8 deletions
@@ -57,11 +57,15 @@ class UploadAttachment with EquatableMixin {
if (attachment != null) {
_updateEvent(Right(SuccessAttachmentUploadState(uploadTaskId, attachment, fileInfo)));
} else {
_updateEvent(Left(ErrorAttachmentUploadState(uploadTaskId)));
_updateEvent(Left(ErrorAttachmentUploadState(uploadId: uploadTaskId)));
}
} catch (e) {
logError('UploadAttachment::upload():ERROR: $e');
_updateEvent(Left(ErrorAttachmentUploadState(uploadTaskId)));
if (e is DioError && e.type == DioErrorType.cancel) {
_updateEvent(Left(CancelAttachmentUploadState(uploadTaskId)));
} else {
_updateEvent(Left(ErrorAttachmentUploadState(uploadId: uploadTaskId, exception: e)));
}
} finally {
await _progressStateController.close();
}
@@ -51,13 +51,16 @@ class SuccessAttachmentUploadState extends Success {
];
}
class ErrorAttachmentUploadState extends Failure {
class ErrorAttachmentUploadState extends FeatureFailure {
final UploadTaskId uploadId;
ErrorAttachmentUploadState(this.uploadId);
ErrorAttachmentUploadState({
required this.uploadId,
dynamic exception
}) : super(exception: exception);
@override
List<Object?> get props => [uploadId];
List<Object?> get props => [uploadId, ...super.props];
}
class CancelAttachmentUploadState extends Failure {
@@ -258,7 +258,7 @@ class UploadController extends BaseController {
if (currentContext != null && currentOverlayContext != null) {
_appToast.showToastErrorMessage(
currentOverlayContext!,
AppLocalizations.of(currentContext!).can_not_upload_this_file_as_attachments,
'${AppLocalizations.of(currentContext!).can_not_upload_this_file_as_attachments}. ${failure.exception ?? ''}',
leadingSVGIconColor: Colors.white,
leadingSVGIcon: _imagePaths.icAttachment);
}