π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Guard Locker UI after asynchronous work
AmanRajSinghMouryafaf89734188e
diff --git a/mobile/apps/locker/lib/ui/pages/collection_page.dart b/mobile/apps/locker/lib/ui/pages/collection_page.dartindex 4aee29ca21..e1f091eb83 100644--- a/mobile/apps/locker/lib/ui/pages/collection_page.dart+++ b/mobile/apps/locker/lib/ui/pages/collection_page.dart@@ -178,6 +178,7 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>}} catch (e, s) {_logger.severe(e, s);+ if (!mounted) return;await showLockerErrorSheet(context, e);}}diff --git a/mobile/apps/locker/lib/ui/pages/trash_page.dart b/mobile/apps/locker/lib/ui/pages/trash_page.dartindex 2c3dc90102..af5459f7ef 100644--- a/mobile/apps/locker/lib/ui/pages/trash_page.dart+++ b/mobile/apps/locker/lib/ui/pages/trash_page.dart@@ -72,26 +72,31 @@ class _TrashPageState extends State<TrashPage> {illustration: LockerBottomSheetIllustration.collectionDelete,);- if (result?.buttonResult.action == ButtonAction.first && mounted) {+ if (result?.buttonResult.action == ButtonAction.first) {await _performEmptyTrash();}}Future<void> _performEmptyTrash() async {if (_trashFiles.isEmpty) {- showToast(context, context.l10n.trashIsEmpty);+ if (mounted) {+ showToast(context, context.l10n.trashIsEmpty);+ }return;}- final dialog = createProgressDialog(- context,- context.l10n.clearingTrash,- isDismissible: false,- );- await dialog.show();+ final dialog = mounted+ ? createProgressDialog(+ context,+ context.l10n.clearingTrash,+ isDismissible: false,+ )+ : null;+ await dialog?.show();try {await TrashService.instance.emptyTrash();- await dialog.hide();+ await dialog?.hide();+ if (!mounted) return;_selectedFiles.clearAll();setState(() {_trashFiles.clear();@@ -99,7 +104,7 @@ class _TrashPageState extends State<TrashPage> {showToast(context, context.l10n.trashClearedSuccessfully);Navigator.of(context).pop();} catch (error) {- await dialog.hide();+ await dialog?.hide();if (mounted) {await showLockerErrorSheet(context, error);}diff --git a/mobile/apps/locker/lib/ui/settings/pages/account_settings_page.dart b/mobile/apps/locker/lib/ui/settings/pages/account_settings_page.dartindex d25944d198..cea616ff72 100644--- a/mobile/apps/locker/lib/ui/settings/pages/account_settings_page.dart+++ b/mobile/apps/locker/lib/ui/settings/pages/account_settings_page.dart@@ -63,61 +63,65 @@ class AccountSettingsPage extends StatelessWidget {final l10n = context.l10n;final hasAuthenticated = await LocalAuthenticationService.instance.requestLocalAuthentication(context, l10n.authToChangeYourEmail);- if (hasAuthenticated) {- // ignore: unawaited_futures- showChangeEmailDialog(context);+ if (!context.mounted || !hasAuthenticated) {+ return;}+ // ignore: unawaited_futures+ showChangeEmailDialog(context);}Future<void> _onRecoveryKeyTapped(BuildContext context) async {final l10n = context.l10n;final hasAuthenticated = await LocalAuthenticationService.instance.requestLocalAuthentication(context, l10n.authToViewYourRecoveryKey);- if (hasAuthenticated) {- String recoveryKey;- try {- recoveryKey = CryptoUtil.bin2hex(- Configuration.instance.getRecoveryKey(),- );- } catch (e) {- await showErrorBottomSheetComponent<void>(- context: context,- message: parseErrorForUI(- context,- context.strings.itLooksLikeSomethingWentWrongPleaseRetryAfterSome,- error: e,- surfaceError: false,- ),- title: context.strings.error,- actionLabel: context.strings.contactSupport,- onActionTap: () async {- await sendLogs(context, "[email protected]", postShare: () {});- },- );- return;- }- await showRecoveryKeySheet(context, recoveryKey: recoveryKey);+ if (!context.mounted || !hasAuthenticated) {+ return;+ }+ String recoveryKey;+ try {+ recoveryKey = CryptoUtil.bin2hex(Configuration.instance.getRecoveryKey());+ } catch (e) {+ await showErrorBottomSheetComponent<void>(+ context: context,+ message: parseErrorForUI(+ context,+ context.strings.itLooksLikeSomethingWentWrongPleaseRetryAfterSome,+ error: e,+ surfaceError: false,+ ),+ title: context.strings.error,+ actionLabel: context.strings.contactSupport,+ onActionTap: () async {+ await sendLogs(context, "[email protected]", postShare: () {});+ },+ );+ return;}+ if (!context.mounted) {+ return;+ }+ await showRecoveryKeySheet(context, recoveryKey: recoveryKey);}Future<void> _onChangePasswordTapped(BuildContext context) async {final l10n = context.l10n;final hasAuthenticated = await LocalAuthenticationService.instance.requestLocalAuthentication(context, l10n.authToChangeYourPassword);- if (hasAuthenticated) {- // ignore: unawaited_futures- Navigator.of(context).push(- MaterialPageRoute(- builder: (BuildContext context) {- return PasswordEntryPage(- Configuration.instance,- PasswordEntryMode.update,- const HomePage(),- );- },- ),- );+ if (!context.mounted || !hasAuthenticated) {+ return;}+ // ignore: unawaited_futures+ Navigator.of(context).push(+ MaterialPageRoute(+ builder: (BuildContext context) {+ return PasswordEntryPage(+ Configuration.instance,+ PasswordEntryMode.update,+ const HomePage(),+ );+ },+ ),+ );}Future<void> _onDeleteAccountTapped(BuildContext context) async {diff --git a/mobile/apps/locker/lib/ui/settings/pages/security_settings_page.dart b/mobile/apps/locker/lib/ui/settings/pages/security_settings_page.dartindex 109f424c89..bb73e0fff6 100644--- a/mobile/apps/locker/lib/ui/settings/pages/security_settings_page.dart+++ b/mobile/apps/locker/lib/ui/settings/pages/security_settings_page.dart@@ -80,10 +80,11 @@ class _SecuritySettingsPageState extends State<SecuritySettingsPage> {context,context.l10n.authToChangeEmailVerificationSetting,);- final isEmailMFAEnabled = UserService.instance.hasEmailMFAEnabled();- if (hasAuthenticated) {- await _updateEmailMFA(!isEmailMFAEnabled);+ if (!hasAuthenticated) {+ return;}+ final isEmailMFAEnabled = UserService.instance.hasEmailMFAEnabled();+ await _updateEmailMFA(!isEmailMFAEnabled);}Widget _buildPasskeyItem(BuildContext context) {@@ -108,16 +109,17 @@ class _SecuritySettingsPageState extends State<SecuritySettingsPage> {context,l10n.authToViewYourActiveSessions,);- if (hasAuthenticated) {- // ignore: unawaited_futures- Navigator.of(context).push(- MaterialPageRoute(- builder: (BuildContext context) {- return SessionsPage(Configuration.instance);- },- ),- );+ if (!context.mounted || !hasAuthenticated) {+ return;}+ // ignore: unawaited_futures+ Navigator.of(context).push(+ MaterialPageRoute(+ builder: (BuildContext context) {+ return SessionsPage(Configuration.instance);+ },+ ),+ );},);}@@ -134,21 +136,27 @@ class _SecuritySettingsPageState extends State<SecuritySettingsPage> {Future<void> _onAppLockTapped(BuildContext context) async {final l10n = context.l10n;- if (await LockScreenSettings.instance.isDeviceSupported()) {+ final isDeviceSupported = await LockScreenSettings.instance+ .isDeviceSupported();+ if (!context.mounted) {+ return;+ }+ if (isDeviceSupported) {final hasAuthenticated = await LocalAuthenticationService.instance.requestLocalAuthentication(context,l10n.authToChangeLockscreenSetting,);- if (hasAuthenticated) {- await Navigator.of(context).push(- MaterialPageRoute(- builder: (BuildContext context) {- return const LockScreenOptions();- },- ),- );+ if (!context.mounted || !hasAuthenticated) {+ return;}+ await Navigator.of(context).push(+ MaterialPageRoute(+ builder: (BuildContext context) {+ return const LockScreenOptions();+ },+ ),+ );} else {await showBottomSheetComponent<void>(context: context,@@ -174,13 +182,14 @@ class _SecuritySettingsPageState extends State<SecuritySettingsPage> {Future<void> _onPasskeyClick(BuildContext buildContext) async {try {+ final reason = buildContext.l10n.authToViewPasskey;final hasAuthenticated = await LocalAuthenticationService.instance.requestLocalAuthentication(- context,- context.l10n.authToViewPasskey,+ buildContext,+ reason,refocusWindows: false,);- if (!hasAuthenticated) {+ if (!buildContext.mounted || !hasAuthenticated) {return;}final isPassKeyResetEnabled = await PasskeyService.instance@@ -196,13 +205,19 @@ class _SecuritySettingsPageState extends State<SecuritySettingsPage> {CryptoUtil.bin2base64(encryptionResult.nonce!),);}+ if (!buildContext.mounted) {+ return;+ }await PasskeyService.instance.openPasskeyPage(buildContext);} catch (e, s) {_logger.severe("failed to open passkey page", e, s);+ if (!buildContext.mounted) {+ return;+ }await showErrorBottomSheetComponent<void>(- context: context,+ context: buildContext,message: e.toString(),- title: context.l10n.somethingWentWrong,+ title: buildContext.l10n.somethingWentWrong,);}}@@ -213,6 +228,9 @@ class _SecuritySettingsPageState extends State<SecuritySettingsPage> {memoryCount: false,);if ((details.profileData?.canDisableEmailMFA ?? false) == false) {+ if (!mounted) {+ return;+ }final result = await Navigator.of(context).push<bool>(MaterialPageRoute(builder: (BuildContext context) {@@ -234,6 +252,9 @@ class _SecuritySettingsPageState extends State<SecuritySettingsPage> {}await UserService.instance.updateEmailMFA(isEnabled);} catch (e) {+ if (!mounted) {+ return;+ }await showErrorBottomSheetComponent<void>(context: context,message: e.toString(),diff --git a/mobile/apps/locker/lib/ui/sharing/manage_links_widget.dart b/mobile/apps/locker/lib/ui/sharing/manage_links_widget.dartindex 0bf6d971f8..09bb92fc5f 100644--- a/mobile/apps/locker/lib/ui/sharing/manage_links_widget.dart+++ b/mobile/apps/locker/lib/ui/sharing/manage_links_widget.dart@@ -91,7 +91,9 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {context,LinkExpiryPickerPage(widget.collection!),).then((value) {- setState(() {});+ if (mounted) {+ setState(() {});+ }}),);},@@ -118,7 +120,9 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {context,DeviceLimitPickerPage(widget.collection!),).then((value) {- setState(() {});+ if (mounted) {+ setState(() {});+ }}),);},@@ -153,7 +157,7 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {password,);await _updateUrlSettings(- context,+ context.mounted ? context : null,propToUpdate,showProgressDialog: false,);@@ -196,6 +200,9 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {showOnlyLoadingState: true,onTap: () async {await Clipboard.setData(ClipboardData(text: urlValue));+ if (!context.mounted) {+ return;+ }showShortToast(context,context.l10n.linkCopiedToClipboard,@@ -245,11 +252,12 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {context,widget.collection!,);- if (result && mounted) {+ if (!context.mounted || !result) {+ return;+ }+ Navigator.of(context).pop();+ if (widget.collection!.isQuickLinkCollection()) {Navigator.of(context).pop();- if (widget.collection!.isQuickLinkCollection()) {- Navigator.of(context).pop();- }}},),@@ -277,11 +285,11 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {}Future<void> _updateUrlSettings(- BuildContext context,+ BuildContext? context,Map<String, dynamic> prop, {bool showProgressDialog = true,}) async {- final dialog = showProgressDialog+ final dialog = showProgressDialog && context != null && context.mounted? createProgressDialog(context, context.l10n.pleaseWait): null;await dialog?.show();@@ -291,13 +299,17 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {prop,);await dialog?.hide();- showShortToast(context, context.l10n.collectionUpdated);+ if (context != null && context.mounted) {+ showShortToast(context, context.l10n.collectionUpdated);+ }if (mounted) {setState(() {});}} catch (e) {await dialog?.hide();- await showLockerErrorSheet(context, e);+ if (context != null && context.mounted) {+ await showLockerErrorSheet(context, e);+ }rethrow;}}diff --git a/mobile/apps/locker/lib/ui/sharing/pickers/device_limit_picker_page.dart b/mobile/apps/locker/lib/ui/sharing/pickers/device_limit_picker_page.dartindex f822037036..f721a490cb 100644--- a/mobile/apps/locker/lib/ui/sharing/pickers/device_limit_picker_page.dart+++ b/mobile/apps/locker/lib/ui/sharing/pickers/device_limit_picker_page.dart@@ -125,11 +125,13 @@ class _ItemsWidgetState extends State<ItemsWidget> {isBottomBorderRadiusRemoved: !isLast,showOnlyLoadingState: true,onTap: () async {- await _updateUrlSettings(context, {'deviceLimit': deviceLimit}).then(- (value) => setState(() {- currentDeviceLimit = deviceLimit;- }),- );+ await _updateUrlSettings(context, {'deviceLimit': deviceLimit});+ if (!mounted) {+ return;+ }+ setState(() {+ currentDeviceLimit = deviceLimit;+ });},);}@@ -144,7 +146,9 @@ class _ItemsWidgetState extends State<ItemsWidget> {prop,);} catch (e) {- await showLockerErrorSheet(context, e);+ if (context.mounted) {+ await showLockerErrorSheet(context, e);+ }rethrow;}}diff --git a/mobile/apps/locker/lib/ui/sharing/pickers/link_expiry_picker_page.dart b/mobile/apps/locker/lib/ui/sharing/pickers/link_expiry_picker_page.dartindex 49eafe61fe..d98f814929 100644--- a/mobile/apps/locker/lib/ui/sharing/pickers/link_expiry_picker_page.dart+++ b/mobile/apps/locker/lib/ui/sharing/pickers/link_expiry_picker_page.dart@@ -139,18 +139,18 @@ class _ItemsWidgetState extends State<ItemsWidget> {debugPrint("Setting expire date to ${DateTime.fromMicrosecondsSinceEpoch(newValidTill)}",);- await updateTime(newValidTill, context);+ await updateTime(newValidTill, context.mounted ? context : null);}},);}- Future<void> updateTime(int newValidTill, BuildContext context) async {+ Future<void> updateTime(int newValidTill, BuildContext? context) async {await _updateUrlSettings(context, {'validTill': newValidTill});}Future<void> _updateUrlSettings(- BuildContext context,+ BuildContext? context,Map<String, dynamic> prop,) async {try {@@ -159,7 +159,9 @@ class _ItemsWidgetState extends State<ItemsWidget> {prop,);} catch (e) {- await showLockerErrorSheet(context, e);+ if (context != null && context.mounted) {+ await showLockerErrorSheet(context, e);+ }rethrow;}}diff --git a/mobile/apps/locker/lib/ui/sharing/share_collection_bottom_sheet.dart b/mobile/apps/locker/lib/ui/sharing/share_collection_bottom_sheet.dartindex d86a338f49..7d4c936d27 100644--- a/mobile/apps/locker/lib/ui/sharing/share_collection_bottom_sheet.dart+++ b/mobile/apps/locker/lib/ui/sharing/share_collection_bottom_sheet.dart@@ -315,7 +315,7 @@ class _ShareCollectionSheetState extends State<ShareCollectionSheet> {}final result = await _collectionActions.addEmailToCollection(- context,+ mounted ? context : null,widget.collection,user.email,role,diff --git a/mobile/apps/locker/lib/ui/utils/legacy_utils.dart b/mobile/apps/locker/lib/ui/utils/legacy_utils.dartindex 692589ee12..0e63f6d1a7 100644--- a/mobile/apps/locker/lib/ui/utils/legacy_utils.dart+++ b/mobile/apps/locker/lib/ui/utils/legacy_utils.dart@@ -1,5 +1,3 @@-// ignore_for_file: use_build_context_synchronously-import "package:ente_legacy/pages/create_legacy_kit_sheet.dart";import "package:ente_legacy/pages/emergency_page.dart";import "package:ente_legacy/pages/legacy_kit_intro_page.dart";diff --git a/mobile/apps/locker/lib/ui/viewer/actions/collection_selection_overlay_bar.dart b/mobile/apps/locker/lib/ui/viewer/actions/collection_selection_overlay_bar.dartindex 1d07e6c5cb..9b8edc67a7 100644--- a/mobile/apps/locker/lib/ui/viewer/actions/collection_selection_overlay_bar.dart+++ b/mobile/apps/locker/lib/ui/viewer/actions/collection_selection_overlay_bar.dart@@ -305,9 +305,13 @@ class _CollectionSelectionOverlayBarStateawait CollectionActions.editCollection(context, collection);} catch (e, s) {_logger.severe(e, s);- await showLockerErrorSheet(context, e);+ if (mounted) {+ await showLockerErrorSheet(context, e);+ }+ }+ if (mounted) {+ widget.selectedCollections.clearAll();}- widget.selectedCollections.clearAll();}Future<void> _deleteCollection(Collection collection) async {@@ -321,9 +325,13 @@ class _CollectionSelectionOverlayBarStateawait CollectionActions.deleteCollection(context, collection);} catch (e, s) {_logger.severe(e, s);- await showLockerErrorSheet(context, e);+ if (mounted) {+ await showLockerErrorSheet(context, e);+ }+ }+ if (mounted) {+ widget.selectedCollections.clearAll();}- widget.selectedCollections.clearAll();}Future<void> _deleteMultipleCollections(Set<Collection> collections) async {@@ -340,9 +348,13 @@ class _CollectionSelectionOverlayBarState);} catch (e, s) {_logger.severe(e, s);- await showLockerErrorSheet(context, e);+ if (mounted) {+ await showLockerErrorSheet(context, e);+ }+ }+ if (mounted) {+ widget.selectedCollections.clearAll();}- widget.selectedCollections.clearAll();}Future<void> _shareCollection(Collection collection) async {@@ -362,9 +374,13 @@ class _CollectionSelectionOverlayBarStateawait showShareCollectionSheet(context, collection: collection);} catch (e, s) {_logger.severe(e, s);- await showLockerErrorSheet(context, e);+ if (mounted) {+ await showLockerErrorSheet(context, e);+ }+ }+ if (mounted) {+ widget.selectedCollections.clearAll();}- widget.selectedCollections.clearAll();}Future<void> _leaveCollections(List<Collection> collections) async {@@ -381,8 +397,12 @@ class _CollectionSelectionOverlayBarState}} catch (e, s) {_logger.severe(e, s);- await showLockerErrorSheet(context, e);+ if (mounted) {+ await showLockerErrorSheet(context, e);+ }+ }+ if (mounted) {+ widget.selectedCollections.clearAll();}- widget.selectedCollections.clearAll();}}diff --git a/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dart b/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dartindex f75ccf89b3..d49a0c4a1a 100644--- a/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dart+++ b/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dart@@ -536,11 +536,20 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {List<EnteFile> files, {required bool shouldRemoveOffline,}) async {- final success = shouldRemoveOffline- ? await OfflineFilesService.instance.unmarkFilesOffline(context, files)- : await OfflineFilesService.instance.markFilesOffline(context, files);+ late final bool success;+ if (shouldRemoveOffline) {+ success = await OfflineFilesService.instance.unmarkFilesOffline(+ context,+ files,+ );+ } else {+ success = await OfflineFilesService.instance.markFilesOffline(+ context,+ files,+ );+ }- if (success) {+ if (success && mounted) {widget.selectedFiles.clearAll();}}@@ -548,7 +557,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {Future<void> _downloadFile(BuildContext context, EnteFile file) async {try {final success = await FileUtil.downloadFile(context, file);- if (success) {+ if (success && mounted) {widget.selectedFiles.clearAll();}} catch (e, stackTrace) {@@ -569,7 +578,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {try {final success = await FileUtil.downloadFiles(context, files);- if (success) {+ if (success && mounted) {widget.selectedFiles.clearAll();}} catch (e, stackTrace) {@@ -596,7 +605,9 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {return;}await FileActions.editFile(context, file);- widget.selectedFiles.clearAll();+ if (mounted) {+ widget.selectedFiles.clearAll();+ }}Future<void> _showAddToDialog(@@ -621,86 +632,98 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {'to add files to.',);+ if (!context.mounted) return;final result = await showAddToCollectionSheet(context,collections: dedupedCollections,);- if (result != null && context.mounted) {- _logger.info(- 'Add-to dialog submitted with '- '${result.selectedCollections.length} selected collection(s).',- );- final dialog = createProgressDialog(- context,- context.l10n.pleaseWait,- isDismissible: false,- );+ if (result == null) return;- await dialog.show();+ _logger.info(+ 'Add-to dialog submitted with '+ '${result.selectedCollections.length} selected collection(s).',+ );+ final dialog = context.mounted+ ? createProgressDialog(+ context,+ context.l10n.pleaseWait,+ isDismissible: false,+ )+ : null;++ await dialog?.show();- try {- final addFutures = <Future<void>>[];+ try {+ final addFutures = <Future<void>>[];- for (final file in ownedFiles) {+ for (final file in ownedFiles) {+ _logger.fine(+ 'Processing file ${file.uploadedFileID} for add-to operation',+ );+ List<Collection> currentCollections;+ try {+ currentCollections = await CollectionService.instance+ .getCollectionsForFile(file);+ } catch (_) {+ _logger.warning(+ 'Failed to fetch existing collections for file ${file.uploadedFileID}',+ );+ currentCollections = <Collection>[];+ }++ final currentCollectionIds = currentCollections+ .map((collection) => collection.id)+ .toSet();++ final collectionsToAdd = result.selectedCollections.where(+ (collection) => !currentCollectionIds.contains(collection.id),+ );++ for (final collection in collectionsToAdd) {_logger.fine(- 'Processing file ${file.uploadedFileID} for add-to operation',+ 'Adding file ${file.uploadedFileID} to collection ${collection.id}.',);- List<Collection> currentCollections;- try {- currentCollections = await CollectionService.instance- .getCollectionsForFile(file);- } catch (_) {- _logger.warning(- 'Failed to fetch existing collections for file ${file.uploadedFileID}',- );- currentCollections = <Collection>[];- }-- final currentCollectionIds = currentCollections- .map((collection) => collection.id)- .toSet();-- final collectionsToAdd = result.selectedCollections.where(- (collection) => !currentCollectionIds.contains(collection.id),+ addFutures.add(+ CollectionService.instance.addToCollection(+ collection,+ file,+ runSync: false,+ ),);-- for (final collection in collectionsToAdd) {- _logger.fine(- 'Adding file ${file.uploadedFileID} to collection ${collection.id}.',- );- addFutures.add(- CollectionService.instance.addToCollection(- collection,- file,- runSync: false,- ),- );- }}+ }- if (addFutures.isEmpty) {- await dialog.hide();+ if (addFutures.isEmpty) {+ await dialog?.hide();+ if (mounted) {widget.selectedFiles.clearAll();+ }+ if (context.mounted) {showToast(context, context.l10n.noChangesWereMade);- return;}+ return;+ }- await Future.wait(addFutures);- await CollectionService.instance.sync();- _logger.info(- 'Completed add-to operation for ${ownedFiles.length} file(s).',- );+ await Future.wait(addFutures);+ await CollectionService.instance.sync();+ _logger.info(+ 'Completed add-to operation for ${ownedFiles.length} file(s).',+ );- await dialog.hide();+ await dialog?.hide();+ if (mounted) {widget.selectedFiles.clearAll();-+ }+ if (context.mounted) {showToast(context, context.l10n.fileUpdatedSuccessfully);- } catch (e) {- await dialog.hide();- _logger.severe('Failed add-to operation: $e');+ }+ } catch (e) {+ await dialog?.hide();+ _logger.severe('Failed add-to operation: $e');+ if (context.mounted) {await showLockerErrorSheet(context, e);}}@@ -716,7 +739,9 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {context,file,onSuccess: () {- widget.selectedFiles.clearAll();+ if (mounted) {+ widget.selectedFiles.clearAll();+ }Bus.instance.fire(CollectionsUpdatedEvent('file_deleted'));},);@@ -743,14 +768,16 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {return;}- final dialog = createProgressDialog(- context,- context.l10n.deletingFile,- isDismissible: false,- );+ final dialog = context.mounted+ ? createProgressDialog(+ context,+ context.l10n.deletingFile,+ isDismissible: false,+ )+ : null;try {- await dialog.show();+ await dialog?.show();for (final file in ownedFiles) {final collections = await CollectionService.instance@@ -761,13 +788,16 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {}}- await dialog.hide();+ await dialog?.hide();- widget.selectedFiles.clearAll();-- showToast(context, context.l10n.fileDeletedSuccessfully);+ if (mounted) {+ widget.selectedFiles.clearAll();+ }+ if (context.mounted) {+ showToast(context, context.l10n.fileDeletedSuccessfully);+ }} catch (e, stackTrace) {- await dialog.hide();+ await dialog?.hide();_logger.severe('Failed to delete files via selection bar: $e',@@ -791,7 +821,9 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {context,file,onSuccess: () {- widget.selectedFiles.clearAll();+ if (mounted) {+ widget.selectedFiles.clearAll();+ }Bus.instance.fire(CollectionsUpdatedEvent('file_important_toggled'));},);@@ -810,7 +842,9 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {context,ownedFiles,onSuccess: () {- widget.selectedFiles.clearAll();+ if (mounted) {+ widget.selectedFiles.clearAll();+ }Bus.instance.fire(CollectionsUpdatedEvent('files_marked_important'));},);@@ -824,6 +858,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {);final dedupedCollections = uniqueCollectionsById(allCollections);+ if (!context.mounted) return;final result = await showAddToCollectionSheet(context,collections: dedupedCollections,@@ -833,24 +868,26 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {return;}- if (!context.mounted) return;-final targetCollection = result.selectedCollections.first;- final dialog = createProgressDialog(- context,- context.l10n.restoringFiles,- isDismissible: false,- );+ final dialog = context.mounted+ ? createProgressDialog(+ context,+ context.l10n.restoringFiles,+ isDismissible: false,+ )+ : null;- await dialog.show();+ await dialog?.show();try {await TrashService.instance.restore(files, targetCollection);- await dialog.hide();+ await dialog?.hide();- widget.selectedFiles.clearAll();+ if (mounted) {+ widget.selectedFiles.clearAll();+ }if (context.mounted) {showToast(@@ -859,7 +896,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {);}} catch (e, stackTrace) {- await dialog.hide();+ await dialog?.hide();_logger.severe('Failed to restore files: $e', e, stackTrace);if (context.mounted) {@@ -884,28 +921,32 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {return;}- final dialog = createProgressDialog(- context,- context.l10n.deletingFiles,- isDismissible: false,- );+ final dialog = context.mounted+ ? createProgressDialog(+ context,+ context.l10n.deletingFiles,+ isDismissible: false,+ )+ : null;- await dialog.show();+ await dialog?.show();try {await TrashService.instance.deleteFromTrash(files);Bus.instance.fire(CollectionsUpdatedEvent('files_deleted_from_trash'));- await dialog.hide();+ await dialog?.hide();- widget.selectedFiles.clearAll();+ if (mounted) {+ widget.selectedFiles.clearAll();+ }if (context.mounted) {showToast(context, context.l10n.filesDeletedPermanently(files.length));}} catch (e, stackTrace) {- await dialog.hide();+ await dialog?.hide();_logger.severe('Failed to delete files from trash: $e', e, stackTrace);if (context.mounted) {