From d7cad625e45dafe5318797e3caa90e959761fea1 Mon Sep 17 00:00:00 2001 From: HuyNguyen Date: Tue, 19 Mar 2024 15:18:43 +0700 Subject: [PATCH] TW-1453: Error handling when update profile fail --- .../settings_profile/settings_profile.dart | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/pages/settings_dashboard/settings_profile/settings_profile.dart b/lib/pages/settings_dashboard/settings_profile/settings_profile.dart index 24294b30ac..ada07b9f99 100644 --- a/lib/pages/settings_dashboard/settings_profile/settings_profile.dart +++ b/lib/pages/settings_dashboard/settings_profile/settings_profile.dart @@ -5,6 +5,7 @@ import 'package:fluffychat/app_state/failure.dart'; import 'package:fluffychat/app_state/success.dart'; import 'package:fluffychat/di/global/get_it_initializer.dart'; import 'package:fluffychat/domain/app_state/room/upload_content_state.dart'; +import 'package:fluffychat/domain/app_state/settings/update_profile_failure.dart'; import 'package:fluffychat/domain/app_state/settings/update_profile_success.dart'; import 'package:fluffychat/domain/usecase/room/upload_content_for_web_interactor.dart'; import 'package:fluffychat/domain/usecase/room/upload_content_interactor.dart'; @@ -375,6 +376,19 @@ class SettingsProfileController extends State Logs().e( 'SettingsProfile::_handleUploadAvatarOnData() - failure: $failure', ); + if (failure is UploadContentFailed) { + TwakeDialog.hideLoadingDialog(context); + TwakeSnackBar.show( + context, + failure.exception.toString(), + ); + } else if (failure is FileTooBigMatrix) { + TwakeDialog.hideLoadingDialog(context); + TwakeSnackBar.show( + context, + failure.fileTooBigMatrixException.toString(), + ); + } }, (success) { Logs().d( @@ -437,6 +451,9 @@ class SettingsProfileController extends State Logs().e( 'SettingsProfile::_handleUploadProfileOnData() - failure: $failure', ); + if (failure is UpdateProfileFailure) { + _handleUpdateProfileFailure(failure.exception.toString()); + } }, (success) { Logs().d( @@ -447,7 +464,8 @@ class SettingsProfileController extends State final newProfile = Profile( userId: client.userID!, displayName: success.displayName ?? displayName, - avatarUrl: success.avatar, + avatarUrl: + success.avatar == null ? currentProfile?.avatarUrl : null, ); _sendAccountDataEvent(profile: newProfile); if (!success.isDeleteAvatar) { @@ -549,6 +567,18 @@ class SettingsProfileController extends State }); } + void _handleUpdateProfileFailure(String errorMessage) { + TwakeDialog.hideLoadingDialog(context); + TwakeSnackBar.show( + context, + errorMessage, + ); + _clearImageInLocal(); + if (currentProfile != null) { + _sendAccountDataEvent(profile: currentProfile!); + } + } + @override void initState() { _handleViewState();