Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Enable synchronous build context lint for Photos

Neeraj Gupta2cbae5e7b613
diff --git a/mobile/apps/photos/analysis_options.yaml b/mobile/apps/photos/analysis_options.yaml
index 4853339722..7b0b5da5d7 100644
--- a/mobile/apps/photos/analysis_options.yaml
+++ b/mobile/apps/photos/analysis_options.yaml
@@ -3,6 +3,7 @@ include: ../../analysis_options.yaml
analyzer:
errors:
deprecated_member_use: warning
+ use_build_context_synchronously: error
exclude:
- thirdparty/**
- lib/generated/**
diff --git a/mobile/apps/photos/lib/emergency/emergency_page.dart b/mobile/apps/photos/lib/emergency/emergency_page.dart
index deae7ba904..4d4717ec39 100644
--- a/mobile/apps/photos/lib/emergency/emergency_page.dart
+++ b/mobile/apps/photos/lib/emergency/emergency_page.dart
@@ -367,6 +367,7 @@ class _EmergencyPageState extends State<EmergencyPage> {
if (actionResult.action == TrustedContactAction.revoke) {
final isPending = contact.isPendingInvite();
+ if (!context.mounted) return;
final confirmed = await showAlertBottomSheet<bool>(
context,
title: isPending
@@ -428,6 +429,7 @@ class _EmergencyPageState extends State<EmergencyPage> {
}
} else {
if (mounted) {
+ if (!context.mounted) return;
await showAlertBottomSheet(
context,
title: context.l10n.cannotUpdateRecoveryTime,
@@ -438,6 +440,7 @@ class _EmergencyPageState extends State<EmergencyPage> {
}
} catch (e) {
if (mounted) {
+ if (!context.mounted) return;
showShortToast(
context,
AppLocalizations.of(context).somethingWentWrong,
diff --git a/mobile/apps/photos/lib/emergency/emergency_service.dart b/mobile/apps/photos/lib/emergency/emergency_service.dart
index cf32cd9abe..f5dadb7857 100644
--- a/mobile/apps/photos/lib/emergency/emergency_service.dart
+++ b/mobile/apps/photos/lib/emergency/emergency_service.dart
@@ -65,6 +65,7 @@ class EmergencyContactService {
}
final String? publicKey = await _userService.getPublicKey(email);
if (publicKey == null) {
+ if (!context.mounted) return false;
await showInviteDialog(context, email);
return false;
}
diff --git a/mobile/apps/photos/lib/emergency/other_contact_page.dart b/mobile/apps/photos/lib/emergency/other_contact_page.dart
index 80db90fb12..436cf356a7 100644
--- a/mobile/apps/photos/lib/emergency/other_contact_page.dart
+++ b/mobile/apps/photos/lib/emergency/other_contact_page.dart
@@ -149,6 +149,7 @@ class _OtherContactPageState extends State<OtherContactPage> {
);
if (mounted) {
_fetchData().ignore();
+ if (!context.mounted) return;
await showAlertBottomSheet(
context,
title: context.l10n.recoveryInitiated,
@@ -160,6 +161,7 @@ class _OtherContactPageState extends State<OtherContactPage> {
);
}
} catch (e) {
+ if (!context.mounted) return;
showGenericErrorBottomSheet(
context: context,
error: e,
@@ -263,6 +265,7 @@ class _OtherContactPageState extends State<OtherContactPage> {
_fetchData().ignore();
}
} catch (e) {
+ if (!mounted) return;
showGenericErrorBottomSheet(context: context, error: e).ignore();
}
}
@@ -293,6 +296,7 @@ class _OtherContactPageState extends State<OtherContactPage> {
Navigator.of(context).pop();
}
} catch (e) {
+ if (!mounted) return;
showGenericErrorBottomSheet(context: context, error: e).ignore();
}
}
diff --git a/mobile/apps/photos/lib/emergency/recover_others_account.dart b/mobile/apps/photos/lib/emergency/recover_others_account.dart
index d24ea5b0bc..894d256628 100644
--- a/mobile/apps/photos/lib/emergency/recover_others_account.dart
+++ b/mobile/apps/photos/lib/emergency/recover_others_account.dart
@@ -94,6 +94,7 @@ class _RecoverOthersAccountState extends State<RecoverOthersAccount> {
onTap: isFormValid
? () async {
await _updatePassword();
+ if (!context.mounted) return;
FocusScope.of(context).unfocus();
}
: null,
@@ -281,14 +282,17 @@ class _RecoverOthersAccountState extends State<RecoverOthersAccount> {
widget.sessions,
);
await dialog.hide();
+ if (!mounted) return;
showShortToast(
context,
AppLocalizations.of(context).passwordChangedSuccessfully,
);
+ if (!mounted) return;
Navigator.of(context).pop();
} catch (e, s) {
_logger.severe("Failed to recover account", e, s);
await dialog.hide();
+ if (!mounted) return;
showGenericErrorBottomSheet(context: context, error: e).ignore();
}
}
diff --git a/mobile/apps/photos/lib/emergency/select_contact_page.dart b/mobile/apps/photos/lib/emergency/select_contact_page.dart
index 0274e17439..e9097274c2 100644
--- a/mobile/apps/photos/lib/emergency/select_contact_page.dart
+++ b/mobile/apps/photos/lib/emergency/select_contact_page.dart
@@ -210,6 +210,7 @@ class _AddContactSheetState extends State<AddContactSheet> {
var hasSuccess = false;
for (final email in emailsToAdd) {
try {
+ if (!mounted) return;
final success = await EmergencyContactService.instance.addContact(
context,
email,
diff --git a/mobile/apps/photos/lib/models/search/search_types.dart b/mobile/apps/photos/lib/models/search/search_types.dart
index f80da20bc5..f8b45d7752 100644
--- a/mobile/apps/photos/lib/models/search/search_types.dart
+++ b/mobile/apps/photos/lib/models/search/search_types.dart
@@ -197,6 +197,7 @@ extension SectionTypeExtensions on SectionType {
return () async {
final centerPoint = await showPickCenterPointSheet(context);
if (centerPoint != null) {
+ if (!context.mounted) return;
showAddLocationSheet(context, centerPoint);
}
};
@@ -222,8 +223,10 @@ extension SectionTypeExtensions on SectionType {
.createAlbum(text);
// Close the dialog now so that it does not flash when leaving the album again.
+ if (!context.mounted) return;
Navigator.of(context).pop();
+ if (!context.mounted) return;
// ignore: unawaited_futures
await routeToPage(
context,
@@ -238,6 +241,7 @@ extension SectionTypeExtensions on SectionType {
},
);
if (result is Exception) {
+ if (!context.mounted) return;
await showGenericErrorDialog(context: context, error: result);
}
};
diff --git a/mobile/apps/photos/lib/services/account/billing_service.dart b/mobile/apps/photos/lib/services/account/billing_service.dart
index ef409d6657..0d11c72464 100644
--- a/mobile/apps/photos/lib/services/account/billing_service.dart
+++ b/mobile/apps/photos/lib/services/account/billing_service.dart
@@ -136,6 +136,7 @@ class BillingService {
),
);
} catch (e) {
+ if (!context.mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
}
diff --git a/mobile/apps/photos/lib/services/account/passkey_service.dart b/mobile/apps/photos/lib/services/account/passkey_service.dart
index 699007391c..907c1d1e65 100644
--- a/mobile/apps/photos/lib/services/account/passkey_service.dart
+++ b/mobile/apps/photos/lib/services/account/passkey_service.dart
@@ -40,6 +40,7 @@ class PasskeyService {
await launchUrlString(url, mode: LaunchMode.externalApplication);
} catch (e) {
Logger('PasskeyService').severe("failed to open passkey page", e);
+ if (!context.mounted) return;
showGenericErrorDialog(context: context, error: e).ignore();
}
}
diff --git a/mobile/apps/photos/lib/services/account/user_service.dart b/mobile/apps/photos/lib/services/account/user_service.dart
index 45917c35ad..a6a845fc26 100644
--- a/mobile/apps/photos/lib/services/account/user_service.dart
+++ b/mobile/apps/photos/lib/services/account/user_service.dart
@@ -128,6 +128,7 @@ class UserService {
isMobile: Platform.isIOS || Platform.isAndroid,
);
await dialog.hide();
+ if (!context.mounted) return;
unawaited(
Navigator.of(context).push(
MaterialPageRoute(
@@ -150,6 +151,7 @@ class UserService {
? responseData["code"]
: null;
if (enteErrCode != null && enteErrCode == "USER_ALREADY_REGISTERED") {
+ if (!context.mounted) return;
unawaited(
showAlertBottomSheet(
context,
@@ -159,6 +161,7 @@ class UserService {
),
);
} else if (enteErrCode != null && enteErrCode == "USER_NOT_REGISTERED") {
+ if (!context.mounted) return;
unawaited(
showAlertBottomSheet(
context,
@@ -168,6 +171,7 @@ class UserService {
),
);
} else if (enteErrCode == "USER_SIGNUP_INCOMPLETE") {
+ if (!context.mounted) return;
unawaited(
showAlertBottomSheet(
context,
@@ -177,6 +181,7 @@ class UserService {
),
);
} else if (e.response != null && e.response!.statusCode == 403) {
+ if (!context.mounted) return;
unawaited(
showAlertBottomSheet(
context,
@@ -186,11 +191,13 @@ class UserService {
),
);
} else {
+ if (!context.mounted) return;
unawaited(showGenericErrorBottomSheet(context: context, error: e));
}
} catch (e, s) {
await dialog.hide();
_logger.severe("Failed to send OTT", e, s);
+ if (!context.mounted) return;
unawaited(showGenericErrorBottomSheet(context: context, error: e));
}
}
@@ -281,6 +288,7 @@ class UserService {
try {
await _gateway.logout();
await Configuration.instance.logout();
+ if (!context.mounted) return;
Navigator.of(context).popUntil((route) => route.isFirst);
} catch (e) {
// Determine if we should silently ignore the error and proceed with logout
@@ -311,9 +319,12 @@ class UserService {
_logger.severe("Failed to logout", e);
//This future is for waiting for the dialog from which logout() is called
//to close and only then to show the error dialog.
- Future.delayed(
- const Duration(milliseconds: 150),
- () => showGenericErrorBottomSheet(context: context, error: null),
+ if (!context.mounted) return;
+ unawaited(
+ Future.delayed(const Duration(milliseconds: 150), () {
+ if (!context.mounted) return;
+ showGenericErrorBottomSheet(context: context, error: null);
+ }),
);
}
}
@@ -333,6 +344,7 @@ class UserService {
await _saveConfiguration(response);
if (userPassword == null) {
await dialog.hide();
+ if (!context.mounted) return;
// ignore: unawaited_futures
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(
@@ -354,12 +366,15 @@ class UserService {
}
await dialog.hide();
await flagService.tryRefreshFlags();
- Navigator.of(context).popUntil((route) => route.isFirst);
+ if (context.mounted) {
+ Navigator.of(context).popUntil((route) => route.isFirst);
+ }
Bus.instance.fire(AccountConfiguredEvent());
}
} catch (e) {
_logger.warning(e);
await dialog.hide();
+ if (!context.mounted) return;
await showGenericErrorBottomSheet(context: context, error: e);
}
}
@@ -410,6 +425,7 @@ class UserService {
page = const PasswordEntryPage(mode: PasswordEntryMode.set);
}
}
+ if (!context.mounted) return;
await Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(
builder: (BuildContext context) {
@@ -422,14 +438,17 @@ class UserService {
_logger.info(e);
await dialog.hide();
if (e.response != null && e.response!.statusCode == 410) {
+ if (!context.mounted) return;
await showAlertBottomSheet(
context,
title: AppLocalizations.of(context).oops,
message: AppLocalizations.of(context).yourVerificationCodeHasExpired,
assetPath: 'assets/warning-grey.png',
);
+ if (!context.mounted) return;
Navigator.of(context).pop();
} else {
+ if (!context.mounted) return;
// ignore: unawaited_futures
showAlertBottomSheet(
context,
@@ -443,6 +462,7 @@ class UserService {
} catch (e) {
await dialog.hide();
_logger.warning(e);
+ if (!context.mounted) return;
// ignore: unawaited_futures
showAlertBottomSheet(
context,
@@ -478,17 +498,20 @@ class UserService {
await dialog.show();
try {
await _gateway.changeEmail(email: email, ott: ott);
- await dialog.hide();
- showShortToast(
- context,
- AppLocalizations.of(context).emailChangedTo(newEmail: email),
- );
await setEmail(email);
- Navigator.of(context).popUntil((route) => route.isFirst);
+ await dialog.hide();
+ if (context.mounted) {
+ showShortToast(
+ context,
+ AppLocalizations.of(context).emailChangedTo(newEmail: email),
+ );
+ Navigator.of(context).popUntil((route) => route.isFirst);
+ }
Bus.instance.fire(UserDetailsChangedEvent());
} on DioException catch (e) {
await dialog.hide();
if (e.response != null && e.response!.statusCode == 403) {
+ if (!context.mounted) return;
// ignore: unawaited_futures
showAlertBottomSheet(
context,
@@ -497,6 +520,7 @@ class UserService {
assetPath: 'assets/warning-grey.png',
);
} else {
+ if (!context.mounted) return;
// ignore: unawaited_futures
showAlertBottomSheet(
context,
@@ -510,6 +534,7 @@ class UserService {
} catch (e) {
await dialog.hide();
_logger.warning(e);
+ if (!context.mounted) return;
// ignore: unawaited_futures
showAlertBottomSheet(
context,
@@ -689,9 +714,12 @@ class UserService {
}
await dialog.hide();
if (page is HomeWidget) {
- Navigator.of(context).popUntil((route) => route.isFirst);
+ if (context.mounted) {
+ Navigator.of(context).popUntil((route) => route.isFirst);
+ }
Bus.instance.fire(AccountConfiguredEvent());
} else {
+ if (!context.mounted) return;
// ignore: unawaited_futures
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(
@@ -760,25 +788,29 @@ class UserService {
sessionID: sessionID,
code: code,
);
- await dialog.hide();
- showShortToast(
- context,
- AppLocalizations.of(context).authenticationSuccessful,
- );
await _saveConfiguration(responseData);
- await Navigator.of(context).pushAndRemoveUntil(
- MaterialPageRoute(
- builder: (BuildContext context) {
- return const PasswordReentryPage();
- },
- ),
- (route) => route.isFirst,
- );
+ await dialog.hide();
+ if (context.mounted) {
+ showShortToast(
+ context,
+ AppLocalizations.of(context).authenticationSuccessful,
+ );
+ await Navigator.of(context).pushAndRemoveUntil(
+ MaterialPageRoute(
+ builder: (BuildContext context) {
+ return const PasswordReentryPage();
+ },
+ ),
+ (route) => route.isFirst,
+ );
+ }
} on DioException catch (e) {
await dialog.hide();
_logger.severe(e);
if (e.response != null && e.response!.statusCode == 404) {
+ if (!context.mounted) return;
showToast(context, AppLocalizations.of(context).sessionExpired);
+ if (!context.mounted) return;
await Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(
builder: (BuildContext context) {
@@ -788,6 +820,7 @@ class UserService {
(route) => route.isFirst,
);
} else {
+ if (!context.mounted) return;
// ignore: unawaited_futures
showAlertBottomSheet(
context,
@@ -801,6 +834,7 @@ class UserService {
} catch (e) {
await dialog.hide();
_logger.severe(e);
+ if (!context.mounted) return;
// ignore: unawaited_futures
showAlertBottomSheet(
context,
@@ -831,6 +865,7 @@ class UserService {
);
await dialog.hide();
+ if (!context.mounted) return;
// ignore: unawaited_futures
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(
@@ -849,7 +884,9 @@ class UserService {
await dialog.hide();
_logger.severe('error while recovery 2fa', e);
if (e.response != null && e.response!.statusCode == 404) {
+ if (!context.mounted) return;
showToast(context, AppLocalizations.of(context).sessionExpired);
+ if (!context.mounted) return;
// ignore: unawaited_futures
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(
@@ -860,6 +897,7 @@ class UserService {
(route) => route.isFirst,
);
} else {
+ if (!context.mounted) return;
// ignore: unawaited_futures
showAlertBottomSheet(
context,
@@ -874,6 +912,7 @@ class UserService {
_logger.severe('unexpected error while recovery 2fa', e);
await dialog.hide();
_logger.severe(e);
+ if (!context.mounted) return;
// ignore: unawaited_futures
showAlertBottomSheet(
context,
@@ -918,6 +957,7 @@ class UserService {
);
} catch (e) {
await dialog.hide();
+ if (!context.mounted) return;
await showAlertBottomSheet(
context,
title: AppLocalizations.of(context).incorrectRecoveryKey,
@@ -934,26 +974,30 @@ class UserService {
secret: secret,
twoFactorType: twoFactorTypeToString(type),
);
- await dialog.hide();
- showShortToast(
- context,
- AppLocalizations.of(context).twofactorAuthenticationSuccessfullyReset,
- );
await _saveConfiguration(responseData);
- // ignore: unawaited_futures
- Navigator.of(context).pushAndRemoveUntil(
- MaterialPageRoute(
- builder: (BuildContext context) {
- return const PasswordReentryPage();
- },
- ),
- (route) => route.isFirst,
- );
+ await dialog.hide();
+ if (context.mounted) {
+ showShortToast(
+ context,
+ AppLocalizations.of(context).twofactorAuthenticationSuccessfullyReset,
+ );
+ // ignore: unawaited_futures
+ Navigator.of(context).pushAndRemoveUntil(
+ MaterialPageRoute(
+ builder: (BuildContext context) {
+ return const PasswordReentryPage();
+ },
+ ),
+ (route) => route.isFirst,
+ );
+ }
} on DioException catch (e) {
await dialog.hide();
_logger.severe("error during recovery", e);
if (e.response != null && e.response!.statusCode == 404) {
+ if (!context.mounted) return;
showToast(context, AppLocalizations.of(context).sessionExpired);
+ if (!context.mounted) return;
// ignore: unawaited_futures
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(
@@ -964,6 +1008,7 @@ class UserService {
(route) => route.isFirst,
);
} else {
+ if (!context.mounted) return;
// ignore: unawaited_futures
showAlertBottomSheet(
context,
@@ -978,6 +1023,7 @@ class UserService {
await dialog.hide();
_logger.severe('unexpcted error during recovery', e);
+ if (!context.mounted) return;
// ignore: unawaited_futures
showAlertBottomSheet(
context,
@@ -999,6 +1045,7 @@ class UserService {
try {
final responseData = await _gateway.setupTwoFactor();
await dialog.hide();
+ if (!context.mounted) return;
unawaited(
routeToPage(
context,
@@ -1026,9 +1073,11 @@ class UserService {
try {
recoveryKey = await getOrCreateRecoveryKey(context);
} catch (e) {
+ if (!context.mounted) return false;
await showGenericErrorBottomSheet(context: context, error: e);
return false;
}
+ if (!context.mounted) return false;
final dialog = createProgressDialog(
context,
AppLocalizations.of(context).verifying,
@@ -1050,7 +1099,9 @@ class UserService {
);
await setTwoFactor(value: true);
await dialog.hide();
- Navigator.pop(context);
+ if (context.mounted) {
+ Navigator.pop(context);
+ }
Bus.instance.fire(UserDetailsChangedEvent());
return true;
} catch (e, s) {
@@ -1058,6 +1109,7 @@ class UserService {
_logger.severe("Failed to enable 2FA", e, s);
if (e is DioException) {
if (e.response != null && e.response!.statusCode == 401) {
+ if (!context.mounted) return false;
// ignore: unawaited_futures
showAlertBottomSheet(
context,
@@ -1070,6 +1122,7 @@ class UserService {
return false;
}
}
+ if (!context.mounted) return false;
// ignore: unawaited_futures
showAlertBottomSheet(
context,
@@ -1094,6 +1147,7 @@ class UserService {
await setTwoFactor(value: false);
await dialog.hide();
Bus.instance.fire(UserDetailsChangedEvent());
+ if (!context.mounted) return;
showShortToast(
context,
AppLocalizations.of(context).twofactorAuthenticationHasBeenDisabled,
@@ -1101,6 +1155,7 @@ class UserService {
} catch (e) {
await dialog.hide();
_logger.severe("Failed to disabled 2FA", e);
+ if (!context.mounted) return;
await showAlertBottomSheet(
context,
title: AppLocalizations.of(context).somethingWentWrong,
diff --git a/mobile/apps/photos/lib/services/collections_service.dart b/mobile/apps/photos/lib/services/collections_service.dart
index 071dbe697e..9da6a0f411 100644
--- a/mobile/apps/photos/lib/services/collections_service.dart
+++ b/mobile/apps/photos/lib/services/collections_service.dart
@@ -1621,6 +1621,7 @@ class CollectionsService {
return collection;
} on PublicCollectionInfoExpiredException catch (e, s) {
_logger.warning("Public collection link expired", e, s);
+ if (!context.mounted) return null;
await showInfoDialog(
context,
title: AppLocalizations.of(context).linkExpired,
@@ -1631,6 +1632,7 @@ class CollectionsService {
return null;
} on PublicCollectionDeviceLimitExceededException catch (e, s) {
_logger.warning("Public collection link device limit reached", e, s);
+ if (!context.mounted) return null;
await showErrorDialog(
context,
AppLocalizations.of(context).canNotOpenTitle,
@@ -1639,6 +1641,7 @@ class CollectionsService {
return null;
} on PublicCollectionRateLimitedException catch (e, s) {
_logger.warning("Public collection link request rate limited", e, s);
+ if (!context.mounted) return null;
await showErrorDialog(
context,
AppLocalizations.of(context).canNotOpenTitle,
@@ -1647,6 +1650,7 @@ class CollectionsService {
return null;
} on PublicCollectionInfoUnauthorizedException catch (e, s) {
_logger.warning("Public collection link is unauthorized", e, s);
+ if (!context.mounted) return null;
await showErrorDialog(
context,
AppLocalizations.of(context).canNotOpenTitle,
@@ -1656,7 +1660,9 @@ class CollectionsService {
} catch (e, s) {
_logger.warning("Failed to fetch public collection", e, s);
_logger.severe("Failed to fetch public collection");
- await showGenericErrorDialog(context: context, error: e);
+ if (context.mounted) {
+ await showGenericErrorDialog(context: context, error: e);
+ }
rethrow;
}
}
@@ -1680,6 +1686,7 @@ class CollectionsService {
return true;
} catch (e) {
_logger.warning("Failed to verify public collection password $e");
+ if (!context.mounted) return false;
await showErrorDialog(
context,
AppLocalizations.of(context).incorrectPasswordTitle,
diff --git a/mobile/apps/photos/lib/services/favorites_service.dart b/mobile/apps/photos/lib/services/favorites_service.dart
index 3eecb4c7af..e2b32be2b3 100644
--- a/mobile/apps/photos/lib/services/favorites_service.dart
+++ b/mobile/apps/photos/lib/services/favorites_service.dart
@@ -181,6 +181,7 @@ class FavoritesService {
await _collectionsService.addOrCopyToCollection(collectionID, files);
} else {
final Collection? favCollection = await getFavoritesCollection();
+ if (!context.mounted) return;
await _collectionActions.moveFilesFromCurrentCollection(
context,
favCollection!,
@@ -216,6 +217,7 @@ class FavoritesService {
"Failed to resolve favorites entry for file ${file.uploadedFileID}",
);
}
+ if (!context.mounted) return;
await _collectionActions.moveFilesFromCurrentCollection(
context,
favCollection,
diff --git a/mobile/apps/photos/lib/services/hidden_service.dart b/mobile/apps/photos/lib/services/hidden_service.dart
index 17f9fba25e..5c3e643657 100644
--- a/mobile/apps/photos/lib/services/hidden_service.dart
+++ b/mobile/apps/photos/lib/services/hidden_service.dart
@@ -283,6 +283,7 @@ extension HiddenService on CollectionsService {
await dialog.hide();
} on AssertionError catch (e) {
await dialog.hide();
+ if (!context.mounted) return false;
unawaited(
showErrorDialog(
context,
@@ -294,6 +295,7 @@ extension HiddenService on CollectionsService {
} catch (e, s) {
_logger.severe("Could not hide", e, s);
await dialog.hide();
+ if (!context.mounted) return false;
await showGenericErrorDialog(context: context, error: e);
return false;
} finally {
@@ -603,10 +605,12 @@ extension HiddenService on CollectionsService {
}
await dialog.hide();
+ if (!context.mounted) return;
showShortToast(context, AppLocalizations.of(context).cleanupComplete);
} catch (e, s) {
_logger.severe("Failed to cleanup hidden files", e, s);
await dialog.hide();
+ if (!context.mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
}
diff --git a/mobile/apps/photos/lib/services/magic_cache_service.dart b/mobile/apps/photos/lib/services/magic_cache_service.dart
index 2d60e8214b..f544a36e03 100644
--- a/mobile/apps/photos/lib/services/magic_cache_service.dart
+++ b/mobile/apps/photos/lib/services/magic_cache_service.dart
@@ -453,6 +453,7 @@ class MagicCacheService {
}
}
for (final p in prompts) {
+ if (!context.mounted) return const [];
final genericSearchResult = toGenericSearchResult(
context,
p,
@@ -517,6 +518,7 @@ class MagicCacheService {
localIdToIntId,
);
}
+ if (!context.mounted) return const [];
final genericSearchResult = toGenericSearchResult(
context,
p,
diff --git a/mobile/apps/photos/lib/services/memories_cache_service.dart b/mobile/apps/photos/lib/services/memories_cache_service.dart
index 77d3aeaeb0..256d0d465c 100644
--- a/mobile/apps/photos/lib/services/memories_cache_service.dart
+++ b/mobile/apps/photos/lib/services/memories_cache_service.dart
@@ -1296,6 +1296,7 @@ class MemoriesCacheService {
);
return;
}
+ if (context == null || !context.mounted) return;
await _routeToPage(
DetailPage(DetailPageConfiguration([file], 0, "memorywidget-fallback")),
context: context,
@@ -1303,6 +1304,7 @@ class MemoriesCacheService {
);
return;
}
+ if (context == null || !context.mounted) return;
await _routeToPage(
AllMemoriesPage(
allMemories: _cachedMemories!,
@@ -1332,6 +1334,7 @@ class MemoriesCacheService {
_logger.warning("Could not find onThisDay memory");
return;
}
+ if (context == null || !context.mounted) return;
await _routeToPage(
AllMemoriesPage(
allMemories: allMemories,
@@ -1383,6 +1386,7 @@ class MemoriesCacheService {
_logger.severe("Person with ID $personID not found");
return;
}
+ if (context == null || !context.mounted) return;
await _routeToPage(
PeoplePage(person: person, searchResult: null),
context: context,
@@ -1390,6 +1394,7 @@ class MemoriesCacheService {
);
return;
}
+ if (context == null || !context.mounted) return;
await _routeToPage(
FullScreenMemoryDataUpdater(
initialIndex: 0,
diff --git a/mobile/apps/photos/lib/services/search_service.dart b/mobile/apps/photos/lib/services/search_service.dart
index 30feeece55..6d86ebee91 100644
--- a/mobile/apps/photos/lib/services/search_service.dart
+++ b/mobile/apps/photos/lib/services/search_service.dart
@@ -448,7 +448,8 @@ class SearchService {
String query,
) async {
final List<GenericSearchResult> searchResults = [];
- for (var month in _getMatchingMonths(context, query)) {
+ final matchingMonths = _getMatchingMonths(context, query).toList();
+ for (final month in matchingMonths) {
final matchedFiles = await FilesDB.instance
.getFilesCreatedWithinDurations(
_getDurationsOfMonthInEveryYear(month.monthNumber),
@@ -594,6 +595,7 @@ class SearchService {
final List<GenericSearchResult> searchResults = [];
final List<EnteFile> allFiles = await getAllFilesForSearch();
for (var fileType in FileType.values) {
+ if (!context.mounted) return const [];
final String fileTypeString = getHumanReadableString(context, fileType);
if (fileTypeString.toLowerCase().startsWith(query.toLowerCase())) {
final matchedFiles = allFiles
@@ -829,7 +831,9 @@ class SearchService {
final locationTagEntities = (await locationService.getLocationTags());
final Map<LocalEntity<LocationTag>, List<EnteFile>> result = {};
final normalizedQuery = query.toLowerCase();
+ if (!context.mounted) return const [];
final noLocationName = AppLocalizations.of(context).noLocation;
+ if (!context.mounted) return const [];
final noLocationTagName = AppLocalizations.of(context).noLocationTag;
final normalizedNoLocationName = noLocationName.toLowerCase();
final normalizedNoLocationTagName = noLocationTagName.toLowerCase();
@@ -1716,6 +1720,7 @@ class SearchService {
} else {
// await two seconds to let new page load first
await Future.delayed(const Duration(seconds: 1));
+ if (!context.mounted) return const [];
final DateTime? pickedTime = await showDatePicker(
context: context,
initialDate: DateTime.now(),
diff --git a/mobile/apps/photos/lib/services/sync/diff_fetcher.dart b/mobile/apps/photos/lib/services/sync/diff_fetcher.dart
index 7f4fc13d0d..69db2f8049 100644
--- a/mobile/apps/photos/lib/services/sync/diff_fetcher.dart
+++ b/mobile/apps/photos/lib/services/sync/diff_fetcher.dart
@@ -103,11 +103,13 @@ class DiffFetcher {
return sharedFiles;
} catch (e, s) {
_logger.severe("Failed to decrypt collection ", e, s);
- await showErrorDialog(
- context,
- AppLocalizations.of(context).somethingWentWrong,
- e.toString(),
- );
+ if (context.mounted) {
+ await showErrorDialog(
+ context,
+ AppLocalizations.of(context).somethingWentWrong,
+ e.toString(),
+ );
+ }
rethrow;
}
}
diff --git a/mobile/apps/photos/lib/services/video_memory_service.dart b/mobile/apps/photos/lib/services/video_memory_service.dart
index 0f74600e59..be0c686c0a 100644
--- a/mobile/apps/photos/lib/services/video_memory_service.dart
+++ b/mobile/apps/photos/lib/services/video_memory_service.dart
@@ -29,6 +29,7 @@ Future<void> createSlideshow(BuildContext context, List<EnteFile> files) async {
await dialog.hide();
}
+ if (!context.mounted) return;
final command = _buildFFmpegCommand(
context,
imageData.paths,
@@ -36,6 +37,7 @@ Future<void> createSlideshow(BuildContext context, List<EnteFile> files) async {
imageData.widths,
);
+ if (!context.mounted) return;
await _executeFFmpegProcess(
context: context,
command: command,
@@ -116,6 +118,7 @@ Future<void> _executeFFmpegProcess({
"FFmpeg command executed successfully in $executionTime seconds",
);
_completeOperation(completer, onComplete);
+ if (!context.mounted) return;
showToast(
context,
AppLocalizations.of(
@@ -126,9 +129,10 @@ Future<void> _executeFFmpegProcess({
_logger.warning(
"FFmpeg process failed with return code $returnCode in $executionTime seconds",
);
- showToast(context, AppLocalizations.of(context).videoExportFailed);
_completeOperation(completer, onComplete);
await FFmpegKit.cancel();
+ if (!context.mounted) return;
+ showToast(context, AppLocalizations.of(context).videoExportFailed);
}
},
(log) {
diff --git a/mobile/apps/photos/lib/services/video_preview_service.dart b/mobile/apps/photos/lib/services/video_preview_service.dart
index f228f4c4c4..d4141d7e61 100644
--- a/mobile/apps/photos/lib/services/video_preview_service.dart
+++ b/mobile/apps/photos/lib/services/video_preview_service.dart
@@ -726,7 +726,11 @@ class VideoPreviewService {
final entry = fileQueue.entries.first;
final file = entry.value;
fileQueue.remove(entry.key);
- await chunkAndUploadVideo(ctx, file, continuation: true);
+ if (ctx != null && ctx.mounted) {
+ await chunkAndUploadVideo(ctx, file, continuation: true);
+ } else {
+ await chunkAndUploadVideo(null, file, continuation: true);
+ }
} else {
// Release compute when queue is empty or network is unavailable
stop(shouldStopProcessing ? "network error" : "nothing to process");
diff --git a/mobile/apps/photos/lib/ui/account/email_entry_page.dart b/mobile/apps/photos/lib/ui/account/email_entry_page.dart
index ab20c0a41e..c89eddd209 100644
--- a/mobile/apps/photos/lib/ui/account/email_entry_page.dart
+++ b/mobile/apps/photos/lib/ui/account/email_entry_page.dart
@@ -307,12 +307,14 @@ class _EmailEntryPageState extends State<EmailEntryPage> {
await UserService.instance.setRefSource(
await _referralSourceForSubmission(),
);
+ if (!mounted) return;
await UserService.instance.sendOtt(
context,
_email!,
isCreateAccountScreen: true,
purpose: "signup",
);
+ if (!mounted) return;
FocusScope.of(context).unfocus();
}
diff --git a/mobile/apps/photos/lib/ui/account/login_page.dart b/mobile/apps/photos/lib/ui/account/login_page.dart
index 208dc17eed..09d9852d19 100644
--- a/mobile/apps/photos/lib/ui/account/login_page.dart
+++ b/mobile/apps/photos/lib/ui/account/login_page.dart
@@ -212,6 +212,7 @@ class _LoginPageState extends State<LoginPage> {
}
}
if (attr != null && !isEmailVerificationEnabled) {
+ if (!mounted) return;
// ignore: unawaited_futures
Navigator.of(context).push(
MaterialPageRoute(
@@ -221,6 +222,7 @@ class _LoginPageState extends State<LoginPage> {
),
);
} else {
+ if (!mounted) return;
await UserService.instance.sendOtt(
context,
_email!,
@@ -228,6 +230,7 @@ class _LoginPageState extends State<LoginPage> {
purpose: "login",
);
}
+ if (!mounted) return;
FocusScope.of(context).unfocus();
}
diff --git a/mobile/apps/photos/lib/ui/account/login_pwd_verification_page.dart b/mobile/apps/photos/lib/ui/account/login_pwd_verification_page.dart
index 74236ade0c..18903477d7 100644
--- a/mobile/apps/photos/lib/ui/account/login_pwd_verification_page.dart
+++ b/mobile/apps/photos/lib/ui/account/login_pwd_verification_page.dart
@@ -162,6 +162,7 @@ class _LoginPasswordVerificationPageState
);
await dialog.show();
try {
+ if (!context.mounted) return;
await UserService.instance.verifyEmailViaPassword(
context,
widget.srpAttributes,
@@ -172,6 +173,7 @@ class _LoginPasswordVerificationPageState
await dialog.hide();
if (e.response != null && e.response!.statusCode == 401) {
_logger.severe('server reject, failed verify SRP login', e, s);
+ if (!context.mounted) return;
await _showContactSupportDialog(
context,
AppLocalizations.of(context).incorrectPasswordTitle,
@@ -182,6 +184,7 @@ class _LoginPasswordVerificationPageState
if (e.type == DioExceptionType.connectionTimeout ||
e.type == DioExceptionType.receiveTimeout ||
e.type == DioExceptionType.sendTimeout) {
+ if (!context.mounted) return;
await _showContactSupportDialog(
context,
AppLocalizations.of(context).noInternetConnection,
@@ -190,6 +193,7 @@ class _LoginPasswordVerificationPageState
).pleaseCheckYourInternetConnectionAndTryAgain,
);
} else {
+ if (!context.mounted) return;
await _showContactSupportDialog(
context,
AppLocalizations.of(context).somethingWentWrong,
@@ -203,6 +207,7 @@ class _LoginPasswordVerificationPageState
if (e is LoginKeyDerivationError) {
_logger.severe('loginKey derivation error', e, s);
// LoginKey err, perform regular login via ott verification
+ if (!context.mounted) return;
await UserService.instance.sendOtt(
context,
email!,
@@ -211,6 +216,7 @@ class _LoginPasswordVerificationPageState
return;
} else if (e is KeyDerivationError) {
// device is not powerful enough to perform derive key
+ if (!context.mounted) return;
final dialogChoice = await showChoiceDialog(
context,
title: AppLocalizations.of(context).recreatePasswordTitle,
@@ -227,6 +233,7 @@ class _LoginPasswordVerificationPageState
return;
} else {
_logger.severe('unexpected error while verifying password', e, s);
+ if (!context.mounted) return;
await _showContactSupportDialog(
context,
AppLocalizations.of(context).oops,
diff --git a/mobile/apps/photos/lib/ui/account/passkey_page.dart b/mobile/apps/photos/lib/ui/account/passkey_page.dart
index 257cca0299..8518fbdf07 100644
--- a/mobile/apps/photos/lib/ui/account/passkey_page.dart
+++ b/mobile/apps/photos/lib/ui/account/passkey_page.dart
@@ -68,22 +68,27 @@ class _PasskeyPageState extends State<PasskeyPage> {
widget.sessionID,
);
} on PassKeySessionNotVerifiedError {
+ if (!mounted) return;
showToast(context, context.l10n.passKeyPendingVerification);
return;
} on PassKeySessionExpiredError {
+ if (!mounted) return;
await showAlertBottomSheet(
context,
title: context.l10n.loginSessionExpired,
message: context.l10n.loginSessionExpiredDetails,
assetPath: 'assets/warning-grey.png',
);
+ if (!mounted) return;
Navigator.of(context).pop();
return;
} catch (e, s) {
_logger.severe("failed to check status", e, s);
+ if (!mounted) return;
showGenericErrorBottomSheet(context: context, error: e).ignore();
return;
}
+ if (!mounted) return;
await UserService.instance.onPassKeyVerified(context, response);
}
@@ -127,6 +132,7 @@ class _PasskeyPageState extends State<PasskeyPage> {
}
} catch (e, s) {
_logger.severe('passKey: failed to handle deeplink', e, s);
+ if (!mounted) return;
showGenericErrorBottomSheet(context: context, error: e).ignore();
}
}
@@ -198,6 +204,7 @@ class _PasskeyPageState extends State<PasskeyPage> {
await checkStatus();
} catch (e) {
debugPrint('failed to check status $e');
+ if (!mounted) return;
showGenericErrorBottomSheet(
context: context,
error: e,
diff --git a/mobile/apps/photos/lib/ui/account/password_entry_page.dart b/mobile/apps/photos/lib/ui/account/password_entry_page.dart
index 46e793a9d9..f7a593ba3a 100644
--- a/mobile/apps/photos/lib/ui/account/password_entry_page.dart
+++ b/mobile/apps/photos/lib/ui/account/password_entry_page.dart
@@ -125,6 +125,7 @@ class _PasswordEntryPageState extends State<PasswordEntryPage> {
} else {
_updatePassword();
}
+ if (!mounted) return;
FocusScope.of(context).unfocus();
}
@@ -317,6 +318,7 @@ class _PasswordEntryPageState extends State<PasswordEntryPage> {
void _updatePassword() async {
final logOutFromOthers = await logOutFromOtherDevices(context);
+ if (!mounted) return;
final dialog = createProgressDialog(
context,
AppLocalizations.of(context).generatingEncryptionKeys,
@@ -332,18 +334,24 @@ class _PasswordEntryPageState extends State<PasswordEntryPage> {
logoutOtherDevices: logOutFromOthers,
);
await dialog.hide();
+ if (widget.mode == PasswordEntryMode.reset) {
+ Bus.instance.fire(SubscriptionPurchasedEvent());
+ }
+ if (!mounted) return;
showShortToast(
context,
AppLocalizations.of(context).passwordChangedSuccessfully,
);
+ if (!mounted) return;
Navigator.of(context).pop();
if (widget.mode == PasswordEntryMode.reset) {
- Bus.instance.fire(SubscriptionPurchasedEvent());
+ if (!mounted) return;
Navigator.of(context).popUntil((route) => route.isFirst);
}
} catch (e, s) {
_logger.severe("Failed to change password", e, s);
await dialog.hide();
+ if (!mounted) return;
await showGenericErrorBottomSheet(context: context, error: e);
}
}
@@ -390,22 +398,26 @@ class _PasswordEntryPageState extends State<PasswordEntryPage> {
await UserService.instance.setAttributes(result);
await dialog.hide();
Configuration.instance.resetVolatilePassword();
- await Navigator.of(context).pushAndRemoveUntil(
- MaterialPageRoute(
- builder: (BuildContext context) {
- return getSubscriptionPage(isOnBoarding: true);
- },
- ),
- (route) => route.isFirst,
- );
+ if (mounted) {
+ await Navigator.of(context).pushAndRemoveUntil(
+ MaterialPageRoute(
+ builder: (BuildContext context) {
+ return getSubscriptionPage(isOnBoarding: true);
+ },
+ ),
+ (route) => route.isFirst,
+ );
+ }
Bus.instance.fire(AccountConfiguredEvent());
} catch (e, s) {
_logger.severe("Failed to configure account", e, s);
await dialog.hide();
+ if (!mounted) return;
await showGenericErrorBottomSheet(context: context, error: e);
}
}
+ if (!mounted) return;
// ignore: unawaited_futures
routeToPage(
context,
diff --git a/mobile/apps/photos/lib/ui/account/password_reentry_page.dart b/mobile/apps/photos/lib/ui/account/password_reentry_page.dart
index 911c33689d..2a3623bfcd 100644
--- a/mobile/apps/photos/lib/ui/account/password_reentry_page.dart
+++ b/mobile/apps/photos/lib/ui/account/password_reentry_page.dart
@@ -113,6 +113,7 @@ class _PasswordReentryPageState extends State<PasswordReentryPage> {
} on KeyDerivationError catch (e, s) {
_logger.severe("Password verification failed", e, s);
await dialog.hide();
+ if (!mounted) return;
final dialogChoice = await showChoiceDialog(
context,
title: AppLocalizations.of(context).recreatePasswordTitle,
@@ -120,6 +121,7 @@ class _PasswordReentryPageState extends State<PasswordReentryPage> {
firstButtonLabel: AppLocalizations.of(context).useRecoveryKey,
);
if (dialogChoice!.action == ButtonAction.first) {
+ if (!mounted) return;
// ignore: unawaited_futures
Navigator.of(context).push(
MaterialPageRoute(
@@ -133,6 +135,7 @@ class _PasswordReentryPageState extends State<PasswordReentryPage> {
} catch (e, s) {
_logger.severe("Password verification failed", e, s);
await dialog.hide();
+ if (!mounted) return;
final dialogChoice = await showChoiceDialog(
context,
title: AppLocalizations.of(context).incorrectPasswordTitle,
@@ -141,6 +144,7 @@ class _PasswordReentryPageState extends State<PasswordReentryPage> {
secondButtonLabel: AppLocalizations.of(context).ok,
);
if (dialogChoice!.action == ButtonAction.first) {
+ if (!mounted) return;
await sendLogs(
context,
AppLocalizations.of(context).contactSupport,
@@ -154,6 +158,7 @@ class _PasswordReentryPageState extends State<PasswordReentryPage> {
Configuration.instance.resetVolatilePassword();
await flagService.tryRefreshFlags();
Bus.instance.fire(SubscriptionPurchasedEvent());
+ if (!mounted) return;
unawaited(
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(
@@ -239,6 +244,7 @@ class _PasswordReentryPageState extends State<PasswordReentryPage> {
await dialog.show();
await Configuration.instance.logout();
await dialog.hide();
+ if (!mounted) return;
Navigator.of(context).popUntil((route) => route.isFirst);
},
),
diff --git a/mobile/apps/photos/lib/ui/account/recovery_key_page.dart b/mobile/apps/photos/lib/ui/account/recovery_key_page.dart
index 06ea1125f3..8f759cf0d0 100644
--- a/mobile/apps/photos/lib/ui/account/recovery_key_page.dart
+++ b/mobile/apps/photos/lib/ui/account/recovery_key_page.dart
@@ -140,6 +140,7 @@ class _RecoveryKeyPageState extends State<RecoveryKeyPage> {
await Clipboard.setData(
ClipboardData(text: recoveryKey),
);
+ if (!mounted) return;
showShortToast(
context,
AppLocalizations.of(
@@ -189,6 +190,7 @@ class _RecoveryKeyPageState extends State<RecoveryKeyPage> {
}
_recoveryKeyFile.writeAsStringSync(recoveryKey);
+ if (!mounted) return null;
await SharePlus.instance.share(
ShareParams(
files: [XFile(_recoveryKeyFile.path)],
diff --git a/mobile/apps/photos/lib/ui/account/recovery_page.dart b/mobile/apps/photos/lib/ui/account/recovery_page.dart
index aa1f11f27f..1a68f9b573 100644
--- a/mobile/apps/photos/lib/ui/account/recovery_page.dart
+++ b/mobile/apps/photos/lib/ui/account/recovery_page.dart
@@ -116,7 +116,9 @@ class _RecoveryPageState extends State<RecoveryPage> {
try {
await Configuration.instance.recover(_recoveryKeyController.text.trim());
await dialog.hide();
+ if (!mounted) return;
showShortToast(context, AppLocalizations.of(context).recoverySuccessful);
+ if (!mounted) return;
// ignore: unawaited_futures
Navigator.of(context).pushReplacement(
MaterialPageRoute(
@@ -130,10 +132,12 @@ class _RecoveryPageState extends State<RecoveryPage> {
);
} catch (e) {
await dialog.hide();
+ if (!mounted) return;
String errMessage = AppLocalizations.of(context).incorrectRecoveryKeyBody;
if (e is AssertionError) {
errMessage = '$errMessage : ${e.message}';
}
+ if (!mounted) return;
// ignore: unawaited_futures
showAlertBottomSheet(
context,
diff --git a/mobile/apps/photos/lib/ui/account/request_pwd_verification_page.dart b/mobile/apps/photos/lib/ui/account/request_pwd_verification_page.dart
index eb75175819..51fa18e4a2 100644
--- a/mobile/apps/photos/lib/ui/account/request_pwd_verification_page.dart
+++ b/mobile/apps/photos/lib/ui/account/request_pwd_verification_page.dart
@@ -102,6 +102,7 @@ class _RequestPasswordVerificationPageState
// pop
await widget.onPasswordVerified(keyEncryptionKey);
await dialog.hide();
+ if (!mounted) return;
Navigator.of(context).pop(true);
} catch (e, s) {
_logger.severe("Error while verifying password", e, s);
@@ -109,6 +110,7 @@ class _RequestPasswordVerificationPageState
if (widget.onPasswordError != null) {
widget.onPasswordError!();
} else {
+ if (!mounted) return;
// ignore: unawaited_futures
showAlertBottomSheet(
context,
diff --git a/mobile/apps/photos/lib/ui/account/sessions_page.dart b/mobile/apps/photos/lib/ui/account/sessions_page.dart
index 1e3e265328..7ccf1bab94 100644
--- a/mobile/apps/photos/lib/ui/account/sessions_page.dart
+++ b/mobile/apps/photos/lib/ui/account/sessions_page.dart
@@ -121,6 +121,7 @@ class _SessionsPageState extends State<SessionsPage> {
} catch (e) {
await dialog.hide();
_logger.severe('failed to terminate');
+ if (!mounted) return;
// ignore: unawaited_futures
showErrorBottomSheetComponent<void>(
context: context,
diff --git a/mobile/apps/photos/lib/ui/account/two_factor_setup_page.dart b/mobile/apps/photos/lib/ui/account/two_factor_setup_page.dart
index 1a2de5ddba..860dc741af 100644
--- a/mobile/apps/photos/lib/ui/account/two_factor_setup_page.dart
+++ b/mobile/apps/photos/lib/ui/account/two_factor_setup_page.dart
@@ -132,6 +132,7 @@ class _TwoFactorSetupPageState extends State<TwoFactorSetupPage>
return GestureDetector(
onTap: () async {
await Clipboard.setData(ClipboardData(text: widget.secretCode));
+ if (!mounted) return;
showShortToast(
context,
AppLocalizations.of(context).codeCopiedToClipboard,
diff --git a/mobile/apps/photos/lib/ui/account/verify_recovery_page.dart b/mobile/apps/photos/lib/ui/account/verify_recovery_page.dart
index d3b7e71d76..7649f8bc55 100644
--- a/mobile/apps/photos/lib/ui/account/verify_recovery_page.dart
+++ b/mobile/apps/photos/lib/ui/account/verify_recovery_page.dart
@@ -41,6 +41,7 @@ class _VerifyRecoveryPageState extends State<VerifyRecoveryPage> {
await dialog.show();
try {
final String inputKey = _recoveryKey.text.trim();
+ if (!mounted) return;
final String recoveryKey = CryptoUtil.bin2hex(
await UserService.instance.getOrCreateRecoveryKey(context),
);
@@ -51,6 +52,7 @@ class _VerifyRecoveryPageState extends State<VerifyRecoveryPage> {
} catch (e) {
await dialog.hide();
if (e is DioException && e.type == DioExceptionType.connectionError) {
+ if (!mounted) return;
await showAlertBottomSheet(
context,
title: AppLocalizations.of(context).noInternetConnection,
@@ -60,18 +62,21 @@ class _VerifyRecoveryPageState extends State<VerifyRecoveryPage> {
assetPath: 'assets/warning-grey.png',
);
} else {
+ if (!mounted) return;
await showGenericErrorBottomSheet(context: context, error: e);
}
return;
}
Bus.instance.fire(NotificationEvent());
await dialog.hide();
+ if (!mounted) return;
await showAlertBottomSheet(
context,
title: AppLocalizations.of(context).recoveryKeyVerified,
message: AppLocalizations.of(context).recoveryKeySuccessBody,
assetPath: 'assets/warning-grey.png',
);
+ if (!mounted) return;
Navigator.of(context).pop();
} else {
throw Exception("recovery key didn't match");
@@ -79,7 +84,9 @@ class _VerifyRecoveryPageState extends State<VerifyRecoveryPage> {
} catch (e, s) {
_logger.severe("failed to verify recovery key", e, s);
await dialog.hide();
+ if (!mounted) return;
final String errMessage = AppLocalizations.of(context).invalidRecoveryKey;
+ if (!mounted) return;
final result = await showChoiceDialog(
context,
title: AppLocalizations.of(context).invalidKey,
@@ -103,9 +110,11 @@ class _VerifyRecoveryPageState extends State<VerifyRecoveryPage> {
if (hasAuthenticated) {
String recoveryKey;
try {
+ if (!mounted) return;
recoveryKey = CryptoUtil.bin2hex(
await UserService.instance.getOrCreateRecoveryKey(context),
);
+ if (!mounted) return;
// ignore: unawaited_futures
routeToPage(
context,
@@ -119,6 +128,7 @@ class _VerifyRecoveryPageState extends State<VerifyRecoveryPage> {
),
);
} catch (e) {
+ if (!mounted) return;
await showGenericErrorBottomSheet(context: context, error: e);
return;
}
diff --git a/mobile/apps/photos/lib/ui/actions/collection/collection_file_actions.dart b/mobile/apps/photos/lib/ui/actions/collection/collection_file_actions.dart
index 1529273e59..2ef12da0b3 100644
--- a/mobile/apps/photos/lib/ui/actions/collection/collection_file_actions.dart
+++ b/mobile/apps/photos/lib/ui/actions/collection/collection_file_actions.dart
@@ -76,6 +76,7 @@ extension CollectionFileActions on CollectionActions {
);
if (actionResult?.action != null &&
actionResult!.action == ButtonAction.error) {
+ if (!context.mounted) return;
await showGenericErrorDialog(
context: context,
error: actionResult.exception,
@@ -172,6 +173,7 @@ extension CollectionFileActions on CollectionActions {
} catch (e, s) {
logger.severe("Failed to add to album", e, s);
await dialog?.hide();
+ if (!context.mounted) return false;
await showGenericErrorDialog(context: context, error: e);
return false;
} finally {
@@ -245,6 +247,7 @@ extension CollectionFileActions on CollectionActions {
);
if (c != null && c.owner.id != currentUserID) {
if (!showProgressDialog) {
+ if (!context.mounted) return false;
dialog = createProgressDialog(
context,
AppLocalizations.of(context).uploadingFilesToAlbum,
@@ -292,7 +295,9 @@ extension CollectionFileActions on CollectionActions {
} catch (e, s) {
logger.severe("Failed to add to album", e, s);
await dialog?.hide();
- await showGenericErrorDialog(context: context, error: e);
+ if (context.mounted) {
+ await showGenericErrorDialog(context: context, error: e);
+ }
rethrow;
}
}
@@ -311,6 +316,7 @@ extension CollectionFileActions on CollectionActions {
await dialog.show();
try {
+ if (!context.mounted) return false;
await FavoritesService.instance.updateFavorites(
context,
files,
@@ -319,6 +325,7 @@ extension CollectionFileActions on CollectionActions {
return true;
} catch (e, s) {
logger.severe("Failed to update favorites", e, s);
+ if (!context.mounted) return false;
showShortToast(
context,
markAsFavorite
diff --git a/mobile/apps/photos/lib/ui/actions/collection/collection_sharing_actions.dart b/mobile/apps/photos/lib/ui/actions/collection/collection_sharing_actions.dart
index 9c428fc1b0..81a38c56ec 100644
--- a/mobile/apps/photos/lib/ui/actions/collection/collection_sharing_actions.dart
+++ b/mobile/apps/photos/lib/ui/actions/collection/collection_sharing_actions.dart
@@ -52,9 +52,11 @@ class CollectionActions {
return true;
} catch (e) {
if (e is SharingNotPermittedForFreeAccountsError) {
+ if (!context.mounted) return false;
await _showUnSupportedAlert(context);
} else {
logger.severe("Failed to update shareUrl collection", e);
+ if (!context.mounted) return false;
await showGenericErrorDialog(context: context, error: e);
}
return false;
@@ -98,6 +100,7 @@ class CollectionActions {
);
if (actionResult?.action != null) {
if (actionResult!.action == ButtonAction.error) {
+ if (!context.mounted) return false;
await showGenericErrorDialog(
context: context,
error: actionResult.exception,
@@ -145,7 +148,9 @@ class CollectionActions {
if (e is SharingNotPermittedForFreeAccountsError) {
if (newCollection.isQuickLinkCollection() &&
!newCollection.hasSharees) {
- await trashCollectionKeepingPhotos(newCollection, context);
+ if (context.mounted) {
+ await trashCollectionKeepingPhotos(newCollection, context);
+ }
}
rethrow;
}
@@ -153,9 +158,11 @@ class CollectionActions {
return collection;
} catch (e, s) {
if (e is SharingNotPermittedForFreeAccountsError) {
+ if (!context.mounted) return null;
await _showUnSupportedAlert(context);
} else {
logger.severe("Failing to create link for selected files", e, s);
+ if (!context.mounted) return null;
await showGenericErrorDialog(context: context, error: e);
}
}
@@ -201,6 +208,7 @@ class CollectionActions {
);
if (actionResult?.action != null) {
if (actionResult!.action == ButtonAction.error) {
+ if (!context.mounted) return false;
await showGenericErrorDialog(
context: context,
error: actionResult.exception,
@@ -231,6 +239,7 @@ class CollectionActions {
} catch (e) {
await dialog?.hide();
logger.severe("Failed to get public key", e);
+ if (!context.mounted) return false;
await showGenericErrorDialog(context: context, error: e);
return false;
}
@@ -239,6 +248,7 @@ class CollectionActions {
if (publicKey == null || publicKey == '') {
// todo: neeraj replace this as per the design where a new screen
// is used for error. Do this change along with handling of network errors
+ if (!context.mounted) return false;
await showInviteDialog(context, email);
return false;
} else {
@@ -286,6 +296,7 @@ class CollectionActions {
} catch (e) {
await dialog?.hide();
logger.severe("Failed to get public key", e);
+ if (!context.mounted) return false;
await showGenericErrorDialog(context: context, error: e);
return false;
}
@@ -294,6 +305,7 @@ class CollectionActions {
if (publicKey == null || publicKey == '') {
// todo: neeraj replace this as per the design where a new screen
// is used for error. Do this change along with handling of network errors
+ if (!context.mounted) return false;
await showDialogWidget(
context: context,
title: AppLocalizations.of(context).inviteToEnte,
@@ -331,9 +343,11 @@ class CollectionActions {
} catch (e) {
await dialog?.hide();
if (e is SharingNotPermittedForFreeAccountsError) {
+ if (!context.mounted) return false;
await _showUnSupportedAlert(context);
} else {
logger.severe("failed to share collection", e);
+ if (!context.mounted) return false;
await showGenericErrorDialog(context: context, error: e);
}
return false;
@@ -392,6 +406,7 @@ class CollectionActions {
return false;
}
}
+ if (!bContext.mounted) return false;
return _showDeleteCollectionConfirmationSheet(
context: bContext,
title: AppLocalizations.of(bContext).deleteAlbumQuestion,
@@ -467,6 +482,7 @@ class CollectionActions {
);
if (actionResult?.action != null &&
actionResult!.action == ButtonAction.error) {
+ if (!context.mounted) return false;
await showGenericErrorDialog(
context: context,
error: actionResult.exception,
@@ -512,6 +528,7 @@ class CollectionActions {
final List<EnteFile> files = await FilesDB.instance.getAllFilesCollection(
collection.id,
);
+ if (!bContext.mounted) return;
await moveFilesFromCurrentCollection(
bContext,
collection,
@@ -530,9 +547,11 @@ class CollectionActions {
final List<EnteFile> files = await FilesDB.instance.getAllFilesCollection(
collection.id,
);
+ if (!bContext.mounted) return;
await moveFilesFromCurrentCollection(bContext, collection, files);
} catch (e) {
logger.severe("Failed to remove files from uncategorized", e);
+ if (!bContext.mounted) return;
await showErrorDialogForException(
context: bContext,
exception: e as Exception,
@@ -619,6 +638,7 @@ class CollectionActions {
}
if (!isCollectionOwner && split.ownedByOtherUsers.isNotEmpty) {
+ if (!context.mounted) return;
showShortToast(
context,
AppLocalizations.of(context).canOnlyRemoveFilesOwnedByYou,
diff --git a/mobile/apps/photos/lib/ui/actions/file/file_actions.dart b/mobile/apps/photos/lib/ui/actions/file/file_actions.dart
index d0c41d05e2..0e3ba0af32 100644
--- a/mobile/apps/photos/lib/ui/actions/file/file_actions.dart
+++ b/mobile/apps/photos/lib/ui/actions/file/file_actions.dart
@@ -31,6 +31,7 @@ Future<void> showSingleFileDeleteSheet(
return;
}
if (Platform.isAndroid && await MediaStoreService.canManageMedia()) {
+ if (!context.mounted) return;
await showBottomSheetComponent<bool>(
context: context,
useRootNavigator: Platform.isIOS,
@@ -54,6 +55,7 @@ Future<void> showSingleFileDeleteSheet(
),
);
} else {
+ if (!context.mounted) return;
final deletedFiles = await deleteFilesOnDeviceOnly(context, [file]);
if (deletedFiles.isNotEmpty &&
((isLocal && !isRemote) || isLocalOnlyContext)) {
@@ -81,6 +83,7 @@ Future<void> showSingleFileDeleteSheet(
},
onDeleteFromRemote: () async {
await deleteFilesFromRemoteOnly(context, [file]);
+ if (!context.mounted) return;
showShortToast(context, l10n.movedToTrash);
if (((isRemote && !isLocal) || !isLocalOnlyContext)) {
onFileRemoved?.call(file);
@@ -93,6 +96,7 @@ Future<void> showSingleFileDeleteSheet(
),
);
if (didDelete == true && isLocal) {
+ if (!context.mounted) return;
await showMediaManagementHintSheet(context);
}
}
diff --git a/mobile/apps/photos/lib/ui/cast/auto.dart b/mobile/apps/photos/lib/ui/cast/auto.dart
index dd925bbc4b..4d47ab70a2 100644
--- a/mobile/apps/photos/lib/ui/cast/auto.dart
+++ b/mobile/apps/photos/lib/ui/cast/auto.dart
@@ -70,6 +70,7 @@ class _AutoCastDialogState extends State<AutoCastDialog> {
setState(() {
_isDeviceTapInProgress.remove(device);
});
+ if (!context.mounted) return;
showGenericErrorDialog(
context: context,
error: e,
diff --git a/mobile/apps/photos/lib/ui/cast/cast.dart b/mobile/apps/photos/lib/ui/cast/cast.dart
index a208ca816d..1e1d82f816 100644
--- a/mobile/apps/photos/lib/ui/cast/cast.dart
+++ b/mobile/apps/photos/lib/ui/cast/cast.dart
@@ -48,10 +48,12 @@ Future<void> showCastSheet(BuildContext context, Collection collection) async {
sessions = await gw.getAllCastSessions();
} catch (e, s) {
logger.severe('Failed to fetch active sessions in cast sheet: ', e, s);
+ if (!context.mounted) return;
await showGenericErrorDialog(context: context, error: e);
return;
}
}
+ if (!context.mounted) return;
return showBottomSheetComponent(
context: context,
builder: (_) => BottomSheetComponent(
diff --git a/mobile/apps/photos/lib/ui/cast/pair_with_auto.dart b/mobile/apps/photos/lib/ui/cast/pair_with_auto.dart
index 96b0830f9c..de446ac73c 100644
--- a/mobile/apps/photos/lib/ui/cast/pair_with_auto.dart
+++ b/mobile/apps/photos/lib/ui/cast/pair_with_auto.dart
@@ -157,6 +157,7 @@ class _PairWithAutoSheetState extends State<_PairWithAutoSheet> {
},
);
} catch (e, s) {
+ if (!context.mounted) return;
await _handleError(context, device, e, s);
}
}
@@ -169,9 +170,11 @@ class _PairWithAutoSheetState extends State<_PairWithAutoSheet> {
try {
await _pairWithAuto(context, widget.collection, code);
if (mounted) {
+ if (!context.mounted) return;
await Navigator.maybePop(context);
}
} catch (e, s) {
+ if (!context.mounted) return;
await _handleError(context, device, e, s);
} finally {
if (mounted) {
diff --git a/mobile/apps/photos/lib/ui/cast/pair_with_code.dart b/mobile/apps/photos/lib/ui/cast/pair_with_code.dart
index e0c471d97e..b97eb8297a 100644
--- a/mobile/apps/photos/lib/ui/cast/pair_with_code.dart
+++ b/mobile/apps/photos/lib/ui/cast/pair_with_code.dart
@@ -93,22 +93,29 @@ class _PairWithCodeSheetState extends State<_PairWithCodeSheet> {
try {
await _pairWithCode(context, widget.collection, _controller.text);
if (mounted) {
+ if (!context.mounted) return;
await Navigator.of(context).maybePop(true);
}
} catch (e, s) {
if (e is _DeviceNotFoundException) {
- showToast(context, l10n.deviceNotFound);
+ if (context.mounted) {
+ showToast(context, l10n.deviceNotFound);
+ }
rethrow;
} else if (e is CastIPMismatchException) {
- await showErrorDialog(
- context,
- l10n.castIPMismatchTitle,
- l10n.castIPMismatchBody,
- );
+ if (context.mounted) {
+ await showErrorDialog(
+ context,
+ l10n.castIPMismatchTitle,
+ l10n.castIPMismatchBody,
+ );
+ }
rethrow;
} else {
logger.severe('Failed to pair with code: ', e, s);
- await showGenericErrorDialog(context: context, error: e);
+ if (context.mounted) {
+ await showGenericErrorDialog(context: context, error: e);
+ }
rethrow;
}
}
diff --git a/mobile/apps/photos/lib/ui/collections/album/row_item.dart b/mobile/apps/photos/lib/ui/collections/album/row_item.dart
index 1acb33c2b4..52b16a600d 100644
--- a/mobile/apps/photos/lib/ui/collections/album/row_item.dart
+++ b/mobile/apps/photos/lib/ui/collections/album/row_item.dart
@@ -336,6 +336,7 @@ class AlbumRowItemWidget extends StatelessWidget {
return;
}
final thumbnail = await CollectionsService.instance.getCover(c);
+ if (!context.mounted) return;
// ignore: unawaited_futures
routeToPage(
context,
diff --git a/mobile/apps/photos/lib/ui/collections/album/smart_album_people.dart b/mobile/apps/photos/lib/ui/collections/album/smart_album_people.dart
index e094f30934..4d5adde219 100644
--- a/mobile/apps/photos/lib/ui/collections/album/smart_album_people.dart
+++ b/mobile/apps/photos/lib/ui/collections/album/smart_album_people.dart
@@ -121,6 +121,7 @@ class _SmartAlbumPeopleState extends State<SmartAlbumPeople> {
.toList();
if (removedPersonIds.isNotEmpty) {
+ if (!context.mounted) return;
final toDelete = await removeFilesDialog(context);
await dialog.show();
@@ -139,6 +140,7 @@ class _SmartAlbumPeopleState extends State<SmartAlbumPeople> {
.getCollectionByID(widget.collectionId);
if (files?.isNotEmpty ?? false) {
+ if (!context.mounted) return;
await CollectionActions(
CollectionsService.instance,
).moveFilesFromCurrentCollection(
@@ -168,6 +170,7 @@ class _SmartAlbumPeopleState extends State<SmartAlbumPeople> {
unawaited(smartAlbumsService.syncSmartAlbums());
await dialog.hide();
+ if (!context.mounted) return;
Navigator.pop(context);
} catch (error, stackTrace) {
_logger.severe(
@@ -176,6 +179,7 @@ class _SmartAlbumPeopleState extends State<SmartAlbumPeople> {
stackTrace,
);
await dialog.hide();
+ if (!context.mounted) return;
await showGenericErrorDialog(
context: context,
error: error,
diff --git a/mobile/apps/photos/lib/ui/collections/album/vertical_list.dart b/mobile/apps/photos/lib/ui/collections/album/vertical_list.dart
index 647c53ec33..7d8399f856 100644
--- a/mobile/apps/photos/lib/ui/collections/album/vertical_list.dart
+++ b/mobile/apps/photos/lib/ui/collections/album/vertical_list.dart
@@ -237,15 +237,19 @@ class _AlbumVerticalListWidgetState extends State<AlbumVerticalListWidget> {
return;
}
+ if (!context.mounted) return;
final success = await _addToCollection(context, item.id, true);
if (success) {
+ if (!context.mounted) return;
showShortToast(
context,
AppLocalizations.of(
context,
).addedSuccessfullyTo(albumName: item.displayName),
);
+ if (!context.mounted) return;
Navigator.pop(context);
+ if (!context.mounted) return;
await _navigateToCollection(context, item);
}
}
@@ -320,8 +324,9 @@ class _AlbumVerticalListWidgetState extends State<AlbumVerticalListWidget> {
popnavAfterSubmission: true,
);
if (result is Exception) {
- await showGenericErrorDialog(context: context, error: result);
_logger.severe("Failed to name album", result);
+ if (!context.mounted) return;
+ await showGenericErrorDialog(context: context, error: result);
}
} else {
Navigator.pop(context);
@@ -351,20 +356,26 @@ class _AlbumVerticalListWidgetState extends State<AlbumVerticalListWidget> {
if (widget.enableSelection) {
Bus.instance.fire(CreateNewAlbumEvent(collection));
} else {
+ if (!context.mounted) return;
if (await _runCollectionAction(
context,
collection,
showProgressDialog: false,
)) {
if (widget.actionType == CollectionActionType.restoreFiles) {
+ if (!context.mounted) return;
showShortToast(context, 'Restored files to album ' + albumName);
} else {
+ if (!context.mounted) return;
showShortToast(context, "Album '" + albumName + "' created.");
}
+ if (!context.mounted) return;
Navigator.pop(context);
+ if (!context.mounted) return;
Navigator.pop(context);
+ if (!context.mounted) return;
await _navigateToCollection(
context,
collection,
@@ -397,6 +408,7 @@ class _AlbumVerticalListWidgetState extends State<AlbumVerticalListWidget> {
bool hasVerifiedLock = false;
if (widget.actionType == CollectionActionType.addFiles) {
+ if (!context.mounted) return;
toastMessage = AppLocalizations.of(
context,
).addedSuccessfullyTo(albumName: item.displayName);
@@ -404,18 +416,21 @@ class _AlbumVerticalListWidgetState extends State<AlbumVerticalListWidget> {
} else if (widget.actionType == CollectionActionType.moveFiles ||
widget.actionType == CollectionActionType.restoreFiles ||
widget.actionType == CollectionActionType.unHide) {
+ if (!context.mounted) return;
toastMessage = AppLocalizations.of(
context,
).movedSuccessfullyTo(albumName: item.displayName);
shouldNavigateToCollection = true;
} else if (widget.actionType ==
CollectionActionType.moveToHiddenCollection) {
+ if (!context.mounted) return;
toastMessage = AppLocalizations.of(
context,
).movedSuccessfullyTo(albumName: item.displayName);
shouldNavigateToCollection = true;
hasVerifiedLock = true;
} else if (widget.actionType == CollectionActionType.addToHiddenAlbum) {
+ if (!context.mounted) return;
toastMessage = AppLocalizations.of(
context,
).addedSuccessfullyTo(albumName: item.displayName);
@@ -425,10 +440,13 @@ class _AlbumVerticalListWidgetState extends State<AlbumVerticalListWidget> {
toastMessage = "";
}
if (toastMessage.isNotEmpty) {
+ if (!context.mounted) return;
showShortToast(context, toastMessage);
}
if (shouldNavigateToCollection) {
+ if (!context.mounted) return;
Navigator.pop(context);
+ if (!context.mounted) return;
await _navigateToCollection(
context,
item,
@@ -540,6 +558,7 @@ class _AlbumVerticalListWidgetState extends State<AlbumVerticalListWidget> {
return true;
} on AssertionError catch (e) {
await dialog.hide();
+ if (!context.mounted) return false;
// ignore: unawaited_futures
showErrorDialog(
context,
@@ -550,6 +569,7 @@ class _AlbumVerticalListWidgetState extends State<AlbumVerticalListWidget> {
} catch (e, s) {
_logger.severe("Could not move to album", e, s);
await dialog.hide();
+ if (!context.mounted) return false;
await showGenericErrorDialog(context: context, error: e);
return false;
}
@@ -577,6 +597,7 @@ class _AlbumVerticalListWidgetState extends State<AlbumVerticalListWidget> {
return true;
} on AssertionError catch (e) {
await dialog.hide();
+ if (!context.mounted) return false;
// ignore: unawaited_futures
showErrorDialog(
context,
@@ -587,6 +608,7 @@ class _AlbumVerticalListWidgetState extends State<AlbumVerticalListWidget> {
} catch (e, s) {
_logger.severe("Could not move to album", e, s);
await dialog.hide();
+ if (!context.mounted) return false;
await showGenericErrorDialog(context: context, error: e);
return false;
}
diff --git a/mobile/apps/photos/lib/ui/collections/collection_action_sheet.dart b/mobile/apps/photos/lib/ui/collections/collection_action_sheet.dart
index b005126808..00335754db 100644
--- a/mobile/apps/photos/lib/ui/collections/collection_action_sheet.dart
+++ b/mobile/apps/photos/lib/ui/collections/collection_action_sheet.dart
@@ -272,6 +272,7 @@ class _CollectionActionSheetState extends State<CollectionActionSheet> {
selectedFiles: widget.selectedFiles?.files.toList(),
);
if (result) {
+ if (!mounted) return;
showShortToast(
context,
AppLocalizations.of(
diff --git a/mobile/apps/photos/lib/ui/collections/flex_grid_view.dart b/mobile/apps/photos/lib/ui/collections/flex_grid_view.dart
index 8c4532827c..1a3fd39eb9 100644
--- a/mobile/apps/photos/lib/ui/collections/flex_grid_view.dart
+++ b/mobile/apps/photos/lib/ui/collections/flex_grid_view.dart
@@ -114,6 +114,7 @@ class _CollectionsFlexiGridViewWidgetState
c.id.toString();
final bool hasVerifiedLock =
widget.sectionType == UISectionType.hiddenCollections;
+ if (!mounted) return;
// ignore: unawaited_futures
routeToPage(
context,
diff --git a/mobile/apps/photos/lib/ui/common/date_input.dart b/mobile/apps/photos/lib/ui/common/date_input.dart
index e7a5b00e07..dc0c90e15c 100644
--- a/mobile/apps/photos/lib/ui/common/date_input.dart
+++ b/mobile/apps/photos/lib/ui/common/date_input.dart
@@ -122,6 +122,7 @@ class _DatePickerFieldState extends State<DatePickerField> {
Future<void> _showDatePicker() async {
final Locale locale = await getFormatLocale();
+ if (!mounted) return;
final DateTime? picked = await showDatePicker(
context: context,
locale: locale,
diff --git a/mobile/apps/photos/lib/ui/components/buttons/button_widget.dart b/mobile/apps/photos/lib/ui/components/buttons/button_widget.dart
index b303fb971d..8c5192490b 100644
--- a/mobile/apps/photos/lib/ui/components/buttons/button_widget.dart
+++ b/mobile/apps/photos/lib/ui/components/buttons/button_widget.dart
@@ -1,3 +1,5 @@
+import 'dart:async';
+
import 'package:ente_pure_utils/ente_pure_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
@@ -501,17 +503,19 @@ class _ButtonChildWidgetState extends State<ButtonChildWidget> {
if (!mounted) return;
setState(() {
executionState = ExecutionState.idle;
- widget.isInAlert
- ? Future.delayed(
- const Duration(seconds: 0),
- () => _popWithButtonAction(
- context,
- buttonAction: ButtonAction.error,
- exception: _exception,
- ),
- )
- : null;
});
+ if (widget.isInAlert) {
+ unawaited(
+ Future.delayed(Duration.zero, () {
+ if (!mounted) return;
+ _popWithButtonAction(
+ context,
+ buttonAction: ButtonAction.error,
+ exception: _exception,
+ );
+ }),
+ );
+ }
}
} else {
if (widget.isInAlert) {
diff --git a/mobile/apps/photos/lib/ui/components/buttons/button_widget_v2.dart b/mobile/apps/photos/lib/ui/components/buttons/button_widget_v2.dart
index 454d16749c..b79bf635be 100644
--- a/mobile/apps/photos/lib/ui/components/buttons/button_widget_v2.dart
+++ b/mobile/apps/photos/lib/ui/components/buttons/button_widget_v2.dart
@@ -494,6 +494,7 @@ class _ButtonWidgetV2State extends State<ButtonWidgetV2>
await Future.delayed(successDisplayDuration);
if (widget.isInAlert) {
+ if (!mounted) return;
_popWithButtonAction(context, buttonAction: widget.buttonAction);
}
diff --git a/mobile/apps/photos/lib/ui/components/text_input_widget.dart b/mobile/apps/photos/lib/ui/components/text_input_widget.dart
index 2b91453311..2255512d4b 100644
--- a/mobile/apps/photos/lib/ui/components/text_input_widget.dart
+++ b/mobile/apps/photos/lib/ui/components/text_input_widget.dart
@@ -1,3 +1,5 @@
+import 'dart:async';
+
import 'package:ente_pure_utils/ente_pure_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@@ -346,13 +348,15 @@ class _TextInputWidgetState extends State<TextInputWidget> {
if (executionState == ExecutionState.error) {
setState(() {
executionState = ExecutionState.idle;
- widget.popNavAfterSubmission
- ? Future.delayed(
- const Duration(seconds: 0),
- () => _popNavigatorStack(context, e: _exception),
- )
- : null;
});
+ if (widget.popNavAfterSubmission) {
+ unawaited(
+ Future.delayed(Duration.zero, () {
+ if (!mounted) return;
+ _popNavigatorStack(context, e: _exception);
+ }),
+ );
+ }
}
} else {
if (widget.popNavAfterSubmission) {
diff --git a/mobile/apps/photos/lib/ui/components/text_input_widget_v2.dart b/mobile/apps/photos/lib/ui/components/text_input_widget_v2.dart
index 4911c7a872..afc2e428c1 100644
--- a/mobile/apps/photos/lib/ui/components/text_input_widget_v2.dart
+++ b/mobile/apps/photos/lib/ui/components/text_input_widget_v2.dart
@@ -1,3 +1,5 @@
+import 'dart:async';
+
import 'package:ente_pure_utils/ente_pure_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@@ -589,6 +591,7 @@ class _TextInputWidgetV2State extends State<TextInputWidgetV2>
),
() {
if (widget.popNavAfterSubmission) {
+ if (!mounted) return;
_popNavigatorStack(context);
}
if (mounted) {
@@ -605,18 +608,25 @@ class _TextInputWidgetV2State extends State<TextInputWidgetV2>
setState(() {
_executionState = ExecutionState.idle;
_syncLoadingController();
- if (widget.popNavAfterSubmission) {
- Future.delayed(
- Duration.zero,
- () => _popNavigatorStack(context, e: _exception),
- );
- }
});
+ if (widget.popNavAfterSubmission) {
+ unawaited(
+ Future.delayed(Duration.zero, () {
+ if (!mounted) return;
+ _popNavigatorStack(context, e: _exception);
+ }),
+ );
+ }
}
} else if (widget.popNavAfterSubmission) {
- Future.delayed(
- Duration(seconds: widget.alwaysShowSuccessState ? 1 : 0),
- () => _popNavigatorStack(context),
+ unawaited(
+ Future.delayed(
+ Duration(seconds: widget.alwaysShowSuccessState ? 1 : 0),
+ () {
+ if (!mounted) return;
+ _popNavigatorStack(context);
+ },
+ ),
);
}
}
diff --git a/mobile/apps/photos/lib/ui/family/invite_members_page.dart b/mobile/apps/photos/lib/ui/family/invite_members_page.dart
index 0183464eed..7846c47e44 100644
--- a/mobile/apps/photos/lib/ui/family/invite_members_page.dart
+++ b/mobile/apps/photos/lib/ui/family/invite_members_page.dart
@@ -359,16 +359,18 @@ class _InviteMembersPageState extends State<InviteMembersPage> {
..clear()
..addAll(failedEmails);
});
- showFamilySnackBar(
- context,
- failedEmails.length == 1
- ? AppLocalizations.of(
- context,
- ).failedToInvite(email: failedEmails.first)
- : AppLocalizations.of(
- context,
- ).failedToInviteCount(count: failedEmails.length),
- );
+ if (mounted) {
+ showFamilySnackBar(
+ context,
+ failedEmails.length == 1
+ ? AppLocalizations.of(
+ context,
+ ).failedToInvite(email: failedEmails.first)
+ : AppLocalizations.of(
+ context,
+ ).failedToInviteCount(count: failedEmails.length),
+ );
+ }
throw const _HandledInviteActionException();
} catch (error) {
if (error is _HandledInviteActionException) {
diff --git a/mobile/apps/photos/lib/ui/growth/apply_code_screen.dart b/mobile/apps/photos/lib/ui/growth/apply_code_screen.dart
index 4bfe6eb2d6..222978615b 100644
--- a/mobile/apps/photos/lib/ui/growth/apply_code_screen.dart
+++ b/mobile/apps/photos/lib/ui/growth/apply_code_screen.dart
@@ -114,6 +114,7 @@ class _ApplyCodeScreenState extends State<ApplyCodeScreen> {
onTap: () async {
try {
await storageBonusService.applyCode(code);
+ if (!context.mounted) return;
// ignore: unawaited_futures
Navigator.of(context).pushReplacement(
MaterialPageRoute(
@@ -127,6 +128,7 @@ class _ApplyCodeScreenState extends State<ApplyCodeScreen> {
Logger(
'$runtimeType',
).severe("failed to apply referral", e);
+ if (!context.mounted) return;
// ignore: unawaited_futures
showErrorDialogForException(
context: context,
diff --git a/mobile/apps/photos/lib/ui/home/grant_permissions_widget.dart b/mobile/apps/photos/lib/ui/home/grant_permissions_widget.dart
index 4d255a2a51..bf2f75d879 100644
--- a/mobile/apps/photos/lib/ui/home/grant_permissions_widget.dart
+++ b/mobile/apps/photos/lib/ui/home/grant_permissions_widget.dart
@@ -185,6 +185,7 @@ class _GrantPermissionsWidgetState extends State<GrantPermissionsWidget> {
}
} catch (e) {
_logger.severe("Failed to request permission: ${e.toString()}", e);
+ if (!mounted) return;
showGenericErrorDialog(context: context, error: e).ignore();
}
}
@@ -201,6 +202,7 @@ class _GrantPermissionsWidgetState extends State<GrantPermissionsWidget> {
}
} catch (e) {
_logger.severe("Failed to request permission: ${e.toString()}", e);
+ if (!mounted) return;
showGenericErrorDialog(context: context, error: e).ignore();
}
}
diff --git a/mobile/apps/photos/lib/ui/home/landing_page_widget.dart b/mobile/apps/photos/lib/ui/home/landing_page_widget.dart
index e7de9b5de6..e7e2c4f2e5 100644
--- a/mobile/apps/photos/lib/ui/home/landing_page_widget.dart
+++ b/mobile/apps/photos/lib/ui/home/landing_page_widget.dart
@@ -206,15 +206,18 @@ class _LandingPageWidgetState extends State<LandingPageWidget> {
),
onTap: () async {
final locale = (await getLocale())!;
+ if (!mounted) return;
unawaited(
routeToPage(
context,
LanguageSelectorPage(appSupportedLocales, (locale) async {
await setLocale(locale);
+ if (!mounted) return;
EnteApp.setLocale(context, locale);
unawaited(AppLocalizations.delegate.load(locale));
}, locale),
).then((value) {
+ if (!mounted) return;
setState(() {});
}),
);
diff --git a/mobile/apps/photos/lib/ui/home/loading_photos_widget.dart b/mobile/apps/photos/lib/ui/home/loading_photos_widget.dart
index 01b71b65fb..9b5bfa37af 100644
--- a/mobile/apps/photos/lib/ui/home/loading_photos_widget.dart
+++ b/mobile/apps/photos/lib/ui/home/loading_photos_widget.dart
@@ -128,6 +128,7 @@ class _LoadingPhotosWidgetState extends State<LoadingPhotosWidget> {
} else {
_importProgressEvent = Bus.instance.on<LocalImportProgressEvent>().listen(
(event) {
+ if (!mounted) return;
_loadingMessage = AppLocalizations.of(
context,
).processingImport(folderName: event.folderName);
diff --git a/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart b/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart
index e9027fdbb6..72100c0bee 100644
--- a/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart
+++ b/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart
@@ -383,6 +383,7 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
_detailSheetEventSubscription = Bus.instance.on<DetailsSheetEvent>().listen(
(event) {
+ if (!mounted) return;
final inheritedData = FullScreenMemoryData.of(context);
if (inheritedData == null) return;
final index = inheritedData.indexNotifier.value;
diff --git a/mobile/apps/photos/lib/ui/map/map_screen.dart b/mobile/apps/photos/lib/ui/map/map_screen.dart
index af4311d18d..bc284d2b61 100644
--- a/mobile/apps/photos/lib/ui/map/map_screen.dart
+++ b/mobile/apps/photos/lib/ui/map/map_screen.dart
@@ -90,6 +90,7 @@ class _MapScreenState extends State<MapScreen> {
final List<ImageMarker> tempMarkers = result.$2;
if (tempMarkers.isEmpty) {
+ if (!mounted) return;
showShortToast(
context,
AppLocalizations.of(context).noImagesWithLocation,
diff --git a/mobile/apps/photos/lib/ui/notification/toast.dart b/mobile/apps/photos/lib/ui/notification/toast.dart
index 9281a91a9b..8632b7a531 100644
--- a/mobile/apps/photos/lib/ui/notification/toast.dart
+++ b/mobile/apps/photos/lib/ui/notification/toast.dart
@@ -16,6 +16,7 @@ void showToast(
}) async {
if (Platform.isAndroid) {
await Fluttertoast.cancel();
+ if (!context.mounted) return;
unawaited(
Fluttertoast.showToast(
msg: message,
diff --git a/mobile/apps/photos/lib/ui/payment/payment_web_page.dart b/mobile/apps/photos/lib/ui/payment/payment_web_page.dart
index 1b1c2e3f29..69bf5176ad 100644
--- a/mobile/apps/photos/lib/ui/payment/payment_web_page.dart
+++ b/mobile/apps/photos/lib/ui/payment/payment_web_page.dart
@@ -57,6 +57,7 @@ class _PaymentWebPageState extends State<PaymentWebPage> {
if (didPop) return;
final shouldPop = await _buildPageExitWidget(context);
if (shouldPop) {
+ if (!context.mounted) return;
Navigator.of(context).pop();
}
},
@@ -216,6 +217,7 @@ class _PaymentWebPageState extends State<PaymentWebPage> {
],
),
);
+ if (!mounted) return;
Navigator.of(context).pop(true);
}
@@ -229,15 +231,18 @@ class _PaymentWebPageState extends State<PaymentWebPage> {
checkoutSessionID,
paymentProvider: stripe,
);
+ if (!mounted) return;
final content = widget.actionType == 'buy'
? AppLocalizations.of(context).yourPurchaseWasSuccessful
: AppLocalizations.of(context).yourSubscriptionWasUpdatedSuccessfully;
+ if (!mounted) return;
await _showExitPageDialog(
title: AppLocalizations.of(context).thankYou,
content: content,
);
} catch (error) {
_logger.severe(error);
+ if (!mounted) return;
await _showExitPageDialog(
title: AppLocalizations.of(context).failedToVerifyPaymentStatus,
content: AppLocalizations.of(
@@ -248,8 +253,9 @@ class _PaymentWebPageState extends State<PaymentWebPage> {
}
// warn the user to wait for sometime before trying another payment
- Future<dynamic> _showExitPageDialog({String? title, String? content}) {
- return showDialog(
+ Future<dynamic> _showExitPageDialog({String? title, String? content}) async {
+ if (!mounted) return null;
+ await showDialog(
useRootNavigator: false,
context: context,
barrierDismissible: false,
@@ -270,6 +276,8 @@ class _PaymentWebPageState extends State<PaymentWebPage> {
),
],
),
- ).then((val) => Navigator.pop(context, true));
+ );
+ if (!mounted) return null;
+ return Navigator.pop(context, true);
}
}
diff --git a/mobile/apps/photos/lib/ui/payment/store_subscription_page.dart b/mobile/apps/photos/lib/ui/payment/store_subscription_page.dart
index 50794ceb84..ef0efce24f 100644
--- a/mobile/apps/photos/lib/ui/payment/store_subscription_page.dart
+++ b/mobile/apps/photos/lib/ui/payment/store_subscription_page.dart
@@ -394,12 +394,14 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {
if (!context.mounted) {
return;
}
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: error);
return;
}
if (!context.mounted) {
return;
}
+ if (!mounted) return;
await _billingService.launchFamilyPortal(
context,
userDetails,
@@ -589,6 +591,7 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {
"Could not find products: " + response.notFoundIDs.toString();
_logger.severe(errMsg);
await _dialog.hide();
+ if (!mounted) return;
await showGenericErrorDialog(
context: context,
error: Exception(errMsg),
@@ -602,6 +605,7 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {
_currentSubscription!.productID != plan.androidID;
if (isCrossGradingOnAndroid) {
await _dialog.hide();
+ if (!mounted) return;
// ignore: unawaited_futures
showErrorDialog(
context,
@@ -740,6 +744,7 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {
"Could not find products: " + response.notFoundIDs.toString();
_logger.severe(errMsg);
await _dialog.hide();
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: Exception(errMsg));
return;
}
@@ -750,6 +755,7 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {
_currentSubscription!.productID != selectedPlan.androidID;
if (isCrossGradingOnAndroid) {
await _dialog.hide();
+ if (!mounted) return;
await showErrorDialog(
context,
AppLocalizations.of(context).couldNotUpdateSubscription,
diff --git a/mobile/apps/photos/lib/ui/payment/stripe_subscription_page.dart b/mobile/apps/photos/lib/ui/payment/stripe_subscription_page.dart
index bd24ec816b..67d7e8e6ff 100644
--- a/mobile/apps/photos/lib/ui/payment/stripe_subscription_page.dart
+++ b/mobile/apps/photos/lib/ui/payment/stripe_subscription_page.dart
@@ -120,6 +120,7 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
try {
await _fetchSub();
} catch (e) {
+ if (!mounted) return;
showToast(
context,
AppLocalizations.of(context).failedToRefreshStripeSubscription,
@@ -132,6 +133,7 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
_currentSubscription != null &&
_currentSubscription!.isValid() &&
_currentSubscription!.productID != freeProductID) {
+ if (!mounted) return;
Navigator.of(context).popUntil((route) => route.isFirst);
}
}
@@ -266,12 +268,14 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
if (!context.mounted) {
return;
}
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: error);
return;
}
if (!context.mounted) {
return;
}
+ if (!mounted) return;
await _billingService.launchFamilyPortal(
context,
userDetails,
@@ -364,6 +368,7 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
try {
final String url = await _billingService.getStripeCustomerPortalUrl();
await _dialog.hide();
+ if (!mounted) return;
await Navigator.of(context)
.push(
MaterialPageRoute(
@@ -378,6 +383,7 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
.then((value) => onWebPaymentGoBack);
} catch (e) {
await _dialog.hide();
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
}
@@ -439,6 +445,7 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
: await _billingService.cancelStripeSubscription();
await _fetchSub();
} catch (e) {
+ if (!mounted) return;
showShortToast(
context,
isAutoRenewDisabled
@@ -564,6 +571,7 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
return;
}
}
+ if (!mounted) return;
await Navigator.push(
context,
MaterialPageRoute(
@@ -714,6 +722,7 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
return;
}
}
+ if (!mounted) return;
await Navigator.push(
context,
MaterialPageRoute(
diff --git a/mobile/apps/photos/lib/ui/rituals/ritual_camera_page.dart b/mobile/apps/photos/lib/ui/rituals/ritual_camera_page.dart
index 3d192694c6..3f8da9d5eb 100644
--- a/mobile/apps/photos/lib/ui/rituals/ritual_camera_page.dart
+++ b/mobile/apps/photos/lib/ui/rituals/ritual_camera_page.dart
@@ -459,6 +459,7 @@ class _RitualCameraPageState extends State<RitualCameraPage>
);
await _pausePreview();
if (!mounted) return;
+ if (!navContext.mounted) return;
await routeToPage(
navContext,
const AllRitualsScreen(),
diff --git a/mobile/apps/photos/lib/ui/rituals/ritual_editor_dialog.dart b/mobile/apps/photos/lib/ui/rituals/ritual_editor_dialog.dart
index 0f30024caa..853b90aa53 100644
--- a/mobile/apps/photos/lib/ui/rituals/ritual_editor_dialog.dart
+++ b/mobile/apps/photos/lib/ui/rituals/ritual_editor_dialog.dart
@@ -555,6 +555,7 @@ Future<void> _showRitualEditor(BuildContext context, {Ritual? ritual}) async {
await ritualsService.saveRitual(
updated,
);
+ if (!context.mounted) return;
Navigator.of(context).pop();
}
: null,
@@ -617,6 +618,7 @@ Future<Collection?> _pickAlbum(BuildContext context) async {
);
Collection? selected;
+ if (!context.mounted) return null;
await showModalBottomSheet(
context: context,
isScrollControlled: true,
diff --git a/mobile/apps/photos/lib/ui/rituals/ritual_heatmap_card.dart b/mobile/apps/photos/lib/ui/rituals/ritual_heatmap_card.dart
index 76bb9c1286..9045c34720 100644
--- a/mobile/apps/photos/lib/ui/rituals/ritual_heatmap_card.dart
+++ b/mobile/apps/photos/lib/ui/rituals/ritual_heatmap_card.dart
@@ -169,6 +169,7 @@ class _RitualHeatmapCardState extends State<RitualHeatmapCard> {
);
await file.writeAsBytes(data, flush: true);
+ if (!mounted) return;
final shareOrigin = _shareButtonRect(context, _shareButtonKey);
await SharePlus.instance.share(
ShareParams(
diff --git a/mobile/apps/photos/lib/ui/rituals/ritual_page.dart b/mobile/apps/photos/lib/ui/rituals/ritual_page.dart
index 2e155321e1..e4cbbf0c9b 100644
--- a/mobile/apps/photos/lib/ui/rituals/ritual_page.dart
+++ b/mobile/apps/photos/lib/ui/rituals/ritual_page.dart
@@ -126,6 +126,7 @@ class _RitualPageState extends State<RitualPage> {
);
overlay.insert(entry);
final boundary = await _waitForBoundaryReady(repaintKey: repaintKey);
+ if (!mounted) return;
final double pixelRatio = (MediaQuery.devicePixelRatioOf(context) * 1.8)
.clamp(2.4, 3.5);
final ui.Image image = await boundary.toImage(pixelRatio: pixelRatio);
@@ -139,6 +140,7 @@ class _RitualPageState extends State<RitualPage> {
"${dir.path}/ritual_share_${ritual.id}_${DateTime.now().millisecondsSinceEpoch}.png",
);
await file.writeAsBytes(data, flush: true);
+ if (!mounted) return;
await SharePlus.instance.share(
ShareParams(
files: [XFile(file.path)],
diff --git a/mobile/apps/photos/lib/ui/settings/about/about_us_page.dart b/mobile/apps/photos/lib/ui/settings/about/about_us_page.dart
index 88bb311ad1..49440772c9 100644
--- a/mobile/apps/photos/lib/ui/settings/about/about_us_page.dart
+++ b/mobile/apps/photos/lib/ui/settings/about/about_us_page.dart
@@ -98,6 +98,7 @@ class AboutUsPage extends StatelessWidget {
final shouldUpdate = await updateService.shouldUpdate();
await dialog.hide();
if (shouldUpdate) {
+ if (!context.mounted) return;
await showDialog(
useRootNavigator: false,
context: context,
@@ -107,6 +108,7 @@ class AboutUsPage extends StatelessWidget {
barrierColor: Colors.black.withValues(alpha: 0.85),
);
} else {
+ if (!context.mounted) return;
showShortToast(
context,
AppLocalizations.of(context).youAreOnTheLatestVersion,
diff --git a/mobile/apps/photos/lib/ui/settings/account/account_settings_page.dart b/mobile/apps/photos/lib/ui/settings/account/account_settings_page.dart
index 1f688afe03..11bf09ef57 100644
--- a/mobile/apps/photos/lib/ui/settings/account/account_settings_page.dart
+++ b/mobile/apps/photos/lib/ui/settings/account/account_settings_page.dart
@@ -122,6 +122,7 @@ class AccountSettingsPage extends StatelessWidget {
AppLocalizations.of(context).authToChangeYourEmail,
);
if (hasAuthenticated) {
+ if (!context.mounted) return;
unawaited(showChangeEmailBottomSheet(context));
}
}
@@ -133,6 +134,7 @@ class AccountSettingsPage extends StatelessWidget {
AppLocalizations.of(context).authToChangeYourPassword,
);
if (hasAuthenticated) {
+ if (!context.mounted) return;
unawaited(
Navigator.of(context).push(
MaterialPageRoute(
@@ -154,11 +156,14 @@ class AccountSettingsPage extends StatelessWidget {
if (hasAuthenticated) {
String recoveryKey;
try {
+ if (!context.mounted) return;
recoveryKey = await _getOrCreateRecoveryKey(context);
} catch (e) {
+ if (!context.mounted) return;
await showGenericErrorDialog(context: context, error: e);
return;
}
+ if (!context.mounted) return;
unawaited(
Navigator.of(context).push(
MaterialPageRoute(
diff --git a/mobile/apps/photos/lib/ui/settings/appearance/appearance_settings_page.dart b/mobile/apps/photos/lib/ui/settings/appearance/appearance_settings_page.dart
index 85f2c916b1..ba6a8466ea 100644
--- a/mobile/apps/photos/lib/ui/settings/appearance/appearance_settings_page.dart
+++ b/mobile/apps/photos/lib/ui/settings/appearance/appearance_settings_page.dart
@@ -99,10 +99,12 @@ class _AppearanceSettingsPageState extends State<AppearanceSettingsPage> {
Future<void> _onLanguageTap(BuildContext context) async {
final locale = (await getLocale())!;
+ if (!context.mounted) return;
await routeToPage(
context,
LanguageSelectorPage(appSupportedLocales, (locale) async {
await setLocale(locale);
+ if (!context.mounted) return;
EnteApp.setLocale(context, locale);
}, locale),
);
diff --git a/mobile/apps/photos/lib/ui/settings/backup/backup_folder_selection_page.dart b/mobile/apps/photos/lib/ui/settings/backup/backup_folder_selection_page.dart
index 2277d54e88..60900214eb 100644
--- a/mobile/apps/photos/lib/ui/settings/backup/backup_folder_selection_page.dart
+++ b/mobile/apps/photos/lib/ui/settings/backup/backup_folder_selection_page.dart
@@ -133,11 +133,13 @@ class _BackupFolderSelectionPageState extends State<BackupFolderSelectionPage> {
}
if (context.mounted) {
+ if (!mounted) return;
Navigator.of(context).pop(true);
}
} catch (e, s) {
_logger.severe("Failed to updated backup folder", e, s);
await dialog.hide();
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
}
@@ -184,6 +186,7 @@ class _BackupFolderSelectionPageState extends State<BackupFolderSelectionPage> {
return false;
}
if (result == _OnlyNewWarningAction.updateSettings) {
+ if (!mounted) return false;
await routeToPage(context, const BackupSettingsScreen());
return false;
}
diff --git a/mobile/apps/photos/lib/ui/settings/backup/backup_settings_screen.dart b/mobile/apps/photos/lib/ui/settings/backup/backup_settings_screen.dart
index bb3878e6ca..3bb2597e62 100644
--- a/mobile/apps/photos/lib/ui/settings/backup/backup_settings_screen.dart
+++ b/mobile/apps/photos/lib/ui/settings/backup/backup_settings_screen.dart
@@ -151,6 +151,7 @@ class _BackupOnlyNewPhotosToggle extends StatelessWidget {
if (!hasPermission) {
return;
}
+ if (!context.mounted) return;
final shouldProceed = await _maybeHandleFolderSelection(
context: context,
);
@@ -228,6 +229,7 @@ class _BackupOnlyNewPhotosToggle extends StatelessWidget {
}
if (result == _FolderPromptAction.selectFolders) {
+ if (!context.mounted) return false;
final bool? selected = await handleFolderSelectionBackupFlow(
context,
fromOnlyNewPhotosToggle: true,
diff --git a/mobile/apps/photos/lib/ui/settings/backup/free_space_options.dart b/mobile/apps/photos/lib/ui/settings/backup/free_space_options.dart
index 61a7bdcbae..dbb4af40a1 100644
--- a/mobile/apps/photos/lib/ui/settings/backup/free_space_options.dart
+++ b/mobile/apps/photos/lib/ui/settings/backup/free_space_options.dart
@@ -138,11 +138,13 @@ class _FreeUpSpaceOptionsScreenState extends State<FreeUpSpaceOptionsScreen> {
try {
status = await FilesService.instance.getFreeableSpaceInfo();
} catch (e) {
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: e);
return;
}
if (status.localIDs.isEmpty) {
+ if (!mounted) return;
unawaited(
showErrorDialog(
context,
@@ -151,6 +153,7 @@ class _FreeUpSpaceOptionsScreenState extends State<FreeUpSpaceOptionsScreen> {
),
);
} else {
+ if (!mounted) return;
final bool? result = await routeToPage(context, FreeSpacePage(status));
if (result == true) {
_showSpaceFreedDialog(status);
@@ -163,11 +166,13 @@ class _FreeUpSpaceOptionsScreenState extends State<FreeUpSpaceOptionsScreen> {
try {
duplicates = await DeduplicationService.instance.getDuplicateFiles();
} catch (e) {
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: e);
return;
}
if (duplicates.isEmpty) {
+ if (!mounted) return;
unawaited(
showErrorDialog(
context,
@@ -176,6 +181,7 @@ class _FreeUpSpaceOptionsScreenState extends State<FreeUpSpaceOptionsScreen> {
),
);
} else {
+ if (!mounted) return;
final DeduplicationResult? result = await routeToPage(
context,
DeduplicatePage(duplicates),
@@ -192,11 +198,13 @@ class _FreeUpSpaceOptionsScreenState extends State<FreeUpSpaceOptionsScreen> {
suggestionFileIDs = await CollectionsService.instance
.fetchDeleteSuggestionFileIDs();
} catch (e) {
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: e);
return;
}
if (suggestionFileIDs.isEmpty) {
+ if (!mounted) return;
unawaited(
showErrorDialog(
context,
@@ -205,6 +213,7 @@ class _FreeUpSpaceOptionsScreenState extends State<FreeUpSpaceOptionsScreen> {
),
);
} else {
+ if (!mounted) return;
await routeToPage(context, DeleteSuggestionsPage());
}
}
diff --git a/mobile/apps/photos/lib/ui/settings/cast/cast_settings_page.dart b/mobile/apps/photos/lib/ui/settings/cast/cast_settings_page.dart
index 0d95fcc01a..81c228e9b1 100644
--- a/mobile/apps/photos/lib/ui/settings/cast/cast_settings_page.dart
+++ b/mobile/apps/photos/lib/ui/settings/cast/cast_settings_page.dart
@@ -144,6 +144,7 @@ class _CastSessionsListState extends State<CastSessionsList> {
await gw.revokeSession(session);
} catch (e, s) {
logger.severe('Failed to revoke cast session: ', e, s);
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: e);
return;
}
diff --git a/mobile/apps/photos/lib/ui/settings/debug/debug_settings_page.dart b/mobile/apps/photos/lib/ui/settings/debug/debug_settings_page.dart
index 037403dabf..9ba103d076 100644
--- a/mobile/apps/photos/lib/ui/settings/debug/debug_settings_page.dart
+++ b/mobile/apps/photos/lib/ui/settings/debug/debug_settings_page.dart
@@ -69,7 +69,9 @@ class _DebugSettingsPageState extends State<DebugSettingsPage> {
await localSettings.setInternalUserDisabled(
newValue,
);
+ if (!mounted) return;
setState(() {});
+ if (!context.mounted) return;
showShortToast(
context,
newValue
@@ -96,7 +98,9 @@ class _DebugSettingsPageState extends State<DebugSettingsPage> {
await localSettings.setCFUploadProxyEnabled(
newValue,
);
+ if (!mounted) return;
setState(() {});
+ if (!context.mounted) return;
showShortToast(
context,
newValue
@@ -121,7 +125,9 @@ class _DebugSettingsPageState extends State<DebugSettingsPage> {
.isBGDebugNotificationsEnabled;
await localSettings
.setBGDebugNotificationsEnabled(newValue);
+ if (!mounted) return;
setState(() {});
+ if (!context.mounted) return;
showShortToast(
context,
newValue
@@ -145,7 +151,9 @@ class _DebugSettingsPageState extends State<DebugSettingsPage> {
await localSettings.setEnableDatabaseLogging(
newValue,
);
+ if (!mounted) return;
setState(() {});
+ if (!context.mounted) return;
showShortToast(
context,
newValue
@@ -169,7 +177,9 @@ class _DebugSettingsPageState extends State<DebugSettingsPage> {
.setShowLocalIDOverThumbnails(
!localSettings.showLocalIDOverThumbnails,
);
+ if (!mounted) return;
setState(() {});
+ if (!context.mounted) return;
showShortToast(
context,
localSettings.showLocalIDOverThumbnails
@@ -213,6 +223,7 @@ class _DebugSettingsPageState extends State<DebugSettingsPage> {
trailingIconIsMuted: true,
onTap: () async {
await updateService.resetChangeLog();
+ if (!context.mounted) return;
_showKeyAttributesDialog(context);
},
),
@@ -226,6 +237,7 @@ class _DebugSettingsPageState extends State<DebugSettingsPage> {
trailingIconIsMuted: true,
onTap: () async {
await LocalSyncService.instance.resetLocalSync();
+ if (!context.mounted) return;
showShortToast(context, "Done");
},
),
@@ -240,6 +252,7 @@ class _DebugSettingsPageState extends State<DebugSettingsPage> {
onTap: () async {
await IgnoredFilesService.instance.reset();
SyncService.instance.sync().ignore();
+ if (!context.mounted) return;
showShortToast(context, "Done");
},
),
diff --git a/mobile/apps/photos/lib/ui/settings/debug/ml_debug_settings_page.dart b/mobile/apps/photos/lib/ui/settings/debug/ml_debug_settings_page.dart
index b39bb7a4fe..6c9c1552f0 100644
--- a/mobile/apps/photos/lib/ui/settings/debug/ml_debug_settings_page.dart
+++ b/mobile/apps/photos/lib/ui/settings/debug/ml_debug_settings_page.dart
@@ -795,9 +795,11 @@ class _MLDebugSettingsPageState extends State<MLDebugSettingsPage> {
MLService.instance.debugIndexingDisabled = false;
await MLService.instance.clusterAllImages();
Bus.instance.fire(PeopleChangedEvent());
+ if (!context.mounted) return;
showShortToast(context, "Done");
} catch (e, s) {
logger.warning('clustering failed ', e, s);
+ if (!context.mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
}
@@ -805,9 +807,11 @@ class _MLDebugSettingsPageState extends State<MLDebugSettingsPage> {
Future<void> _onUpdateDiscover(BuildContext context) async {
try {
await magicCacheService.updateCache(forced: true);
+ if (!context.mounted) return;
showShortToast(context, "Done");
} catch (e, s) {
logger.warning('Update discover failed', e, s);
+ if (!context.mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
}
@@ -817,9 +821,11 @@ class _MLDebugSettingsPageState extends State<MLDebugSettingsPage> {
final now = DateTime.now();
await memoriesCacheService.updateCache(forced: true);
final duration = DateTime.now().difference(now);
+ if (!context.mounted) return;
showShortToast(context, "Done in ${duration.inSeconds} seconds");
} catch (e, s) {
logger.warning('Update memories failed', e, s);
+ if (!context.mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
}
@@ -831,9 +837,11 @@ class _MLDebugSettingsPageState extends State<MLDebugSettingsPage> {
Future<void> _onSyncPersonMappings(BuildContext context) async {
try {
await faceRecognitionService.syncPersonFeedback();
+ if (!context.mounted) return;
showShortToast(context, "Done");
} catch (e, s) {
logger.warning('sync person mappings failed ', e, s);
+ if (!context.mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
}
@@ -842,9 +850,11 @@ class _MLDebugSettingsPageState extends State<MLDebugSettingsPage> {
try {
await wrappedService.forceRecompute();
await localSettings.resetWrapped2025Complete();
+ if (!context.mounted) return;
showShortToast(context, "Ente Rewind recomputed");
} catch (e, s) {
logger.severe('Wrapped recompute failed ', e, s);
+ if (!context.mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
}
@@ -854,9 +864,11 @@ class _MLDebugSettingsPageState extends State<MLDebugSettingsPage> {
final now = DateTime.now();
await memoriesCacheService.clearMemoriesCache();
final duration = DateTime.now().difference(now);
+ if (!context.mounted) return;
showShortToast(context, "Done in ${duration.inSeconds} seconds");
} catch (e, s) {
logger.warning('Clear memories cache failed', e, s);
+ if (!context.mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
}
@@ -872,9 +884,11 @@ class _MLDebugSettingsPageState extends State<MLDebugSettingsPage> {
try {
await mlDataDB.dropFacesFeedbackTables();
Bus.instance.fire(PeopleChangedEvent());
+ if (!context.mounted) return;
showShortToast(context, "Done");
} catch (e, s) {
logger.warning('reset feedback failed ', e, s);
+ if (!context.mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
},
@@ -897,9 +911,11 @@ class _MLDebugSettingsPageState extends State<MLDebugSettingsPage> {
}
await mlDataDB.dropClustersAndPersonTable();
Bus.instance.fire(PeopleChangedEvent());
+ if (!context.mounted) return;
showShortToast(context, "Done");
} catch (e, s) {
logger.warning('peopleToPersonMapping remove failed ', e, s);
+ if (!context.mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
},
@@ -917,9 +933,11 @@ class _MLDebugSettingsPageState extends State<MLDebugSettingsPage> {
try {
await mlDataDB.dropClustersAndPersonTable(faces: true);
Bus.instance.fire(PeopleChangedEvent());
+ if (!context.mounted) return;
showShortToast(context, "Done");
} catch (e, s) {
logger.warning('drop feedback failed ', e, s);
+ if (!context.mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
},
@@ -936,9 +954,11 @@ class _MLDebugSettingsPageState extends State<MLDebugSettingsPage> {
firstButtonOnTap: () async {
try {
await SemanticSearchService.instance.clearIndexes();
+ if (!context.mounted) return;
showShortToast(context, "Done");
} catch (e, s) {
logger.warning('drop clip embeddings failed ', e, s);
+ if (!context.mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
},
@@ -958,12 +978,14 @@ class _MLDebugSettingsPageState extends State<MLDebugSettingsPage> {
? ClipVectorDB.localGalleryInstance
: ClipVectorDB.instance;
await vectorDB.deleteIndexFile();
+ if (!context.mounted) return;
showShortToast(context, "Done");
if (mounted) {
setState(() {});
}
} catch (e, s) {
logger.warning('reset usearch index failed ', e, s);
+ if (!context.mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
},
diff --git a/mobile/apps/photos/lib/ui/settings/debug/social_debug_screen.dart b/mobile/apps/photos/lib/ui/settings/debug/social_debug_screen.dart
index d36c2c800d..9beb682de2 100644
--- a/mobile/apps/photos/lib/ui/settings/debug/social_debug_screen.dart
+++ b/mobile/apps/photos/lib/ui/settings/debug/social_debug_screen.dart
@@ -45,6 +45,7 @@ class SocialDebugScreen extends StatelessWidget {
onTap: () async {
await SocialSyncService.instance
.syncAllSharedCollections();
+ if (!context.mounted) return;
showShortToast(context, "Social sync completed");
},
),
@@ -55,6 +56,7 @@ class SocialDebugScreen extends StatelessWidget {
trailingIconIsMuted: true,
onTap: () async {
await CollectionsService.instance.sync();
+ if (!context.mounted) return;
showShortToast(context, "Collection sync completed");
},
),
@@ -65,6 +67,7 @@ class SocialDebugScreen extends StatelessWidget {
trailingIconIsMuted: true,
onTap: () async {
await SocialDB.instance.seedExampleData();
+ if (!context.mounted) return;
showShortToast(context, "Example data seeded");
},
),
@@ -76,6 +79,7 @@ class SocialDebugScreen extends StatelessWidget {
onTap: () async {
final count = await SocialDB.instance
.deleteAllComments();
+ if (!context.mounted) return;
showShortToast(context, "Deleted $count comments");
},
),
@@ -87,6 +91,7 @@ class SocialDebugScreen extends StatelessWidget {
onTap: () async {
final count = await SocialDB.instance
.deleteAllReactions();
+ if (!context.mounted) return;
showShortToast(context, "Deleted $count reactions");
},
),
diff --git a/mobile/apps/photos/lib/ui/settings/developer_settings_page.dart b/mobile/apps/photos/lib/ui/settings/developer_settings_page.dart
index b3756d8a58..c75d780bf6 100644
--- a/mobile/apps/photos/lib/ui/settings/developer_settings_page.dart
+++ b/mobile/apps/photos/lib/ui/settings/developer_settings_page.dart
@@ -78,7 +78,9 @@ class _DeveloperSettingsPageState extends State<DeveloperSettingsPage> {
await _maybeToggleLocalGalleryModeOption(url);
if (modeToggleMessage != null) {
Bus.instance.fire(AppModeChangedEvent());
+ if (!context.mounted) return;
showToast(context, modeToggleMessage);
+ if (!context.mounted) return;
Navigator.of(context).pop();
return;
}
@@ -87,16 +89,19 @@ class _DeveloperSettingsPageState extends State<DeveloperSettingsPage> {
if ((uri.scheme == "http" || uri.scheme == "https")) {
await _ping(url);
await endpointConfig.setEndpoint(url);
+ if (!context.mounted) return;
showToast(
context,
AppLocalizations.of(context).endpointUpdatedMessage,
);
+ if (!context.mounted) return;
Navigator.of(context).pop();
} else {
throw const FormatException();
}
} catch (e) {
_logger.severe("Failed to update developer endpoint", e);
+ if (!context.mounted) return;
await showAlertBottomSheet(
context,
title: AppLocalizations.of(context).invalidEndpoint,
diff --git a/mobile/apps/photos/lib/ui/settings/ml/ml_user_dev_screen.dart b/mobile/apps/photos/lib/ui/settings/ml/ml_user_dev_screen.dart
index c2ef7d5f69..ab5493441d 100644
--- a/mobile/apps/photos/lib/ui/settings/ml/ml_user_dev_screen.dart
+++ b/mobile/apps/photos/lib/ui/settings/ml/ml_user_dev_screen.dart
@@ -151,6 +151,7 @@ class _MLUserDeveloperOptionsState extends State<MLUserDeveloperOptions> {
e,
s,
);
+ if (!context.mounted) return;
await showGenericErrorDialog(
context: context,
error: e,
@@ -196,6 +197,7 @@ class _MLUserDeveloperOptionsState extends State<MLUserDeveloperOptions> {
e,
s,
);
+ if (!context.mounted) return;
await showGenericErrorDialog(
context: context,
error: e,
@@ -232,6 +234,7 @@ class _MLUserDeveloperOptionsState extends State<MLUserDeveloperOptions> {
e,
s,
);
+ if (!context.mounted) return;
await showGenericErrorDialog(
context: context,
error: e,
@@ -254,6 +257,7 @@ class _MLUserDeveloperOptionsState extends State<MLUserDeveloperOptions> {
e,
s,
);
+ if (!context.mounted) return;
await showGenericErrorDialog(
context: context,
error: e,
@@ -276,6 +280,7 @@ class _MLUserDeveloperOptionsState extends State<MLUserDeveloperOptions> {
e,
s,
);
+ if (!context.mounted) return;
await showGenericErrorDialog(
context: context,
error: e,
@@ -298,6 +303,7 @@ class _MLUserDeveloperOptionsState extends State<MLUserDeveloperOptions> {
e,
s,
);
+ if (!context.mounted) return;
await showGenericErrorDialog(
context: context,
error: e,
@@ -323,8 +329,10 @@ class _MLUserDeveloperOptionsState extends State<MLUserDeveloperOptions> {
await mlDataDB.deleteFaceIndexForFiles(emptyFileIDs.toList());
await mlDataDB.deleteClipEmbeddings(emptyFileIDs.toList());
await mlDataDB.deletePetDataForFiles(emptyFileIDs.toList());
+ if (!context.mounted) return;
showShortToast(context, "Deleted ${emptyFileIDs.length} entries");
} catch (e) {
+ if (!context.mounted) return;
// ignore: unawaited_futures
showGenericErrorDialog(context: context, error: e);
}
@@ -335,8 +343,10 @@ class _MLUserDeveloperOptionsState extends State<MLUserDeveloperOptions> {
await mlDataDB.dropClustersAndPersonTable(faces: true);
await SemanticSearchService.instance.clearIndexes();
Bus.instance.fire(PeopleChangedEvent());
+ if (!context.mounted) return;
showShortToast(context, "All local ML cleared");
} catch (e) {
+ if (!context.mounted) return;
// ignore: unawaited_futures
showGenericErrorDialog(context: context, error: e);
}
diff --git a/mobile/apps/photos/lib/ui/settings/security/security_settings_page.dart b/mobile/apps/photos/lib/ui/settings/security/security_settings_page.dart
index 67959e0632..35b62934cd 100644
--- a/mobile/apps/photos/lib/ui/settings/security/security_settings_page.dart
+++ b/mobile/apps/photos/lib/ui/settings/security/security_settings_page.dart
@@ -155,6 +155,7 @@ class _SecuritySettingsPageState extends State<SecuritySettingsPage> {
await _disableTwoFactor();
completer.isCompleted ? null : completer.complete();
} else {
+ if (!context.mounted) return;
await UserService.instance.setupTwoFactor(context, completer);
}
return completer.future;
@@ -203,6 +204,7 @@ class _SecuritySettingsPageState extends State<SecuritySettingsPage> {
memoryCount: false,
);
if ((details.profileData?.canDisableEmailMFA ?? false) == false) {
+ if (!mounted) return;
await routeToPage(
context,
RequestPasswordVerificationPage(
@@ -217,6 +219,7 @@ class _SecuritySettingsPageState extends State<SecuritySettingsPage> {
}
await UserService.instance.updateEmailMFA(isEnabled);
} catch (e) {
+ if (!mounted) return;
showToast(context, AppLocalizations.of(context).somethingWentWrong);
}
}
@@ -228,6 +231,7 @@ class _SecuritySettingsPageState extends State<SecuritySettingsPage> {
AppLocalizations.of(context).authToViewPasskey,
);
if (hasAuthenticated) {
+ if (!context.mounted) return;
await _handlePasskeyClick(context);
}
}
@@ -237,6 +241,7 @@ class _SecuritySettingsPageState extends State<SecuritySettingsPage> {
final isPassKeyResetEnabled = await PasskeyService.instance
.isPasskeyRecoveryEnabled();
if (!isPassKeyResetEnabled) {
+ if (!mounted) return;
final Uint8List recoveryKey = await UserService.instance
.getOrCreateRecoveryKey(context);
final resetKey = CryptoUtil.generateKey();
@@ -248,20 +253,24 @@ class _SecuritySettingsPageState extends State<SecuritySettingsPage> {
CryptoUtil.bin2base64(encryptionResult.nonce!),
);
}
+ if (!buildContext.mounted) return;
PasskeyService.instance.openPasskeyPage(buildContext).ignore();
} catch (e, s) {
_logger.severe("failed to open passkey page", e, s);
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
}
Future<void> _onAppLockTap(BuildContext context) async {
if (await LocalAuthentication().isDeviceSupported()) {
+ if (!context.mounted) return;
final bool result = await requestAuthentication(
context,
AppLocalizations.of(context).authToChangeLockscreenSetting,
);
if (result) {
+ if (!context.mounted) return;
await Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
@@ -271,6 +280,7 @@ class _SecuritySettingsPageState extends State<SecuritySettingsPage> {
);
}
} else {
+ if (!context.mounted) return;
await showErrorDialog(
context,
AppLocalizations.of(context).noSystemLockFound,
@@ -288,6 +298,7 @@ class _SecuritySettingsPageState extends State<SecuritySettingsPage> {
AppLocalizations.of(context).authToViewYourActiveSessions,
);
if (hasAuthenticated) {
+ if (!context.mounted) return;
unawaited(
Navigator.of(context).push(
MaterialPageRoute(
diff --git a/mobile/apps/photos/lib/ui/settings/support/help_support_page.dart b/mobile/apps/photos/lib/ui/settings/support/help_support_page.dart
index 8738fe9fa6..0f0548e9ca 100644
--- a/mobile/apps/photos/lib/ui/settings/support/help_support_page.dart
+++ b/mobile/apps/photos/lib/ui/settings/support/help_support_page.dart
@@ -196,6 +196,7 @@ class HelpSupportPage extends StatelessWidget {
Future<void> _exportLogs(BuildContext context) async {
try {
final zipFilePath = await getZippedLogsFile(context);
+ if (!context.mounted) return;
await exportLogs(context, zipFilePath);
} catch (e, s) {
_logger.severe("Failed to export logs", e, s);
diff --git a/mobile/apps/photos/lib/ui/settings/support/report_issue_page.dart b/mobile/apps/photos/lib/ui/settings/support/report_issue_page.dart
index 409a5e876f..a58cd35403 100644
--- a/mobile/apps/photos/lib/ui/settings/support/report_issue_page.dart
+++ b/mobile/apps/photos/lib/ui/settings/support/report_issue_page.dart
@@ -143,24 +143,30 @@ class _ReportIssuePageState extends State<ReportIssuePage> {
);
if (_attachLogs) {
+ if (!mounted) return;
logsZipFilePath = await getZippedLogsFile(context);
logsLabel = l10n.export;
}
- final didOpenComposer = _attachLogs
- ? await sendLogsWithSubjectAndBody(
- context,
- toEmail: recipientEmail,
- subject: subject,
- body: body,
- zipFilePath: logsZipFilePath,
- )
- : await sendComposedEmail(
- context,
- to: recipientEmail,
- subject: subject,
- body: body,
- );
+ late final bool didOpenComposer;
+ if (_attachLogs) {
+ if (!mounted) return;
+ didOpenComposer = await sendLogsWithSubjectAndBody(
+ context,
+ toEmail: recipientEmail,
+ subject: subject,
+ body: body,
+ zipFilePath: logsZipFilePath,
+ );
+ } else {
+ if (!mounted) return;
+ didOpenComposer = await sendComposedEmail(
+ context,
+ to: recipientEmail,
+ subject: subject,
+ body: body,
+ );
+ }
if (didOpenComposer && mounted) {
Navigator.of(context).pop();
diff --git a/mobile/apps/photos/lib/ui/settings/widgets/albums_widget_settings.dart b/mobile/apps/photos/lib/ui/settings/widgets/albums_widget_settings.dart
index 6b489dcbcc..504b10cd1d 100644
--- a/mobile/apps/photos/lib/ui/settings/widgets/albums_widget_settings.dart
+++ b/mobile/apps/photos/lib/ui/settings/widgets/albums_widget_settings.dart
@@ -114,6 +114,7 @@ class _AlbumsWidgetSettingsState extends State<AlbumsWidgetSettings> {
.toList();
await AlbumHomeWidgetService.instance
.updateSelectedAlbums(albums);
+ if (!context.mounted) return;
Navigator.pop(context);
}
: null,
diff --git a/mobile/apps/photos/lib/ui/settings_page.dart b/mobile/apps/photos/lib/ui/settings_page.dart
index 2ff97365ed..1e4ddae8cd 100644
--- a/mobile/apps/photos/lib/ui/settings_page.dart
+++ b/mobile/apps/photos/lib/ui/settings_page.dart
@@ -334,6 +334,7 @@ class _SettingsBody extends StatelessWidget {
AppLocalizations.of(context).authToManageLegacy,
);
if (hasAuthenticated) {
+ if (!context.mounted) return;
await Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
@@ -453,10 +454,12 @@ class _SettingsBody extends StatelessWidget {
try {
await setMapEnabled(!isEnabled);
} catch (e) {
- showShortToast(
- context,
- AppLocalizations.of(context).somethingWentWrong,
- );
+ if (context.mounted) {
+ showShortToast(
+ context,
+ AppLocalizations.of(context).somethingWentWrong,
+ );
+ }
rethrow;
}
},
diff --git a/mobile/apps/photos/lib/ui/sharing/add_participant_page.dart b/mobile/apps/photos/lib/ui/sharing/add_participant_page.dart
index e198fd6589..cf3aeabbc7 100644
--- a/mobile/apps/photos/lib/ui/sharing/add_participant_page.dart
+++ b/mobile/apps/photos/lib/ui/sharing/add_participant_page.dart
@@ -275,6 +275,7 @@ class _AddParticipantPage extends State<AddParticipantPage> {
}
final noOfSuccessfullAdds = results.where((e) => e).length;
+ if (!mounted) return;
showToast(
context,
AppLocalizations.of(
@@ -316,6 +317,7 @@ class _AddParticipantPage extends State<AddParticipantPage> {
}
final noOfSuccessfullAdds = results.where((e) => e).length;
+ if (!mounted) return;
showToast(
context,
AppLocalizations.of(
@@ -359,6 +361,7 @@ class _AddParticipantPage extends State<AddParticipantPage> {
}
final successful = results.where((e) => e).length;
+ if (!mounted) return;
showToast(
context,
AppLocalizations.of(
diff --git a/mobile/apps/photos/lib/ui/sharing/manage_album_participant.dart b/mobile/apps/photos/lib/ui/sharing/manage_album_participant.dart
index c7fa8550f3..e7f4f8a2c9 100644
--- a/mobile/apps/photos/lib/ui/sharing/manage_album_participant.dart
+++ b/mobile/apps/photos/lib/ui/sharing/manage_album_participant.dart
@@ -111,6 +111,7 @@ class _ManageIndividualParticipantState
if (actionResult?.action != null) {
if (actionResult!.action == ButtonAction.first) {
try {
+ if (!context.mounted) return;
isConvertToViewSuccess = await collectionActions
.addEmailToCollection(
context,
@@ -119,6 +120,7 @@ class _ManageIndividualParticipantState
CollectionParticipantRole.viewer,
);
} catch (e) {
+ if (!context.mounted) return;
await showGenericErrorDialog(
context: context,
error: e,
@@ -157,6 +159,7 @@ class _ManageIndividualParticipantState
);
if ((result) && mounted) {
+ if (!context.mounted) return;
Navigator.of(context).pop(true);
}
},
diff --git a/mobile/apps/photos/lib/ui/sharing/manage_links_widget.dart b/mobile/apps/photos/lib/ui/sharing/manage_links_widget.dart
index 51a07ced0b..da66c19821 100644
--- a/mobile/apps/photos/lib/ui/sharing/manage_links_widget.dart
+++ b/mobile/apps/photos/lib/ui/sharing/manage_links_widget.dart
@@ -190,6 +190,7 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
'enableDownload': selected,
});
if (!selected) {
+ if (!context.mounted) return;
unawaited(
showErrorDialog(
context,
@@ -237,6 +238,7 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
final propToUpdate = await _getEncryptedPassword(
password,
);
+ if (!context.mounted) return;
await _updateUrlSettings(
context,
propToUpdate,
@@ -271,8 +273,10 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
collection,
);
if (result && mounted) {
+ if (!context.mounted) return;
Navigator.of(context).pop();
if (collection.isQuickLinkCollection()) {
+ if (!context.mounted) return;
Navigator.of(context).pop();
}
}
@@ -308,6 +312,7 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
showOnlyLoadingState: true,
onTap: () async {
await Clipboard.setData(ClipboardData(text: urlValue));
+ if (!context.mounted) return;
showShortToast(
context,
AppLocalizations.of(context).linkCopiedToClipboard,
@@ -322,6 +327,7 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
widget.collection!,
);
await Clipboard.setData(ClipboardData(text: embedHtml));
+ if (!context.mounted) return;
showShortToast(
context,
AppLocalizations.of(context).linkCopiedToClipboard,
@@ -453,6 +459,7 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
return;
}
+ if (!context.mounted) return;
await _updateShareUrlFromPicker(context, {
'validTill': timeInMicrosecondsFromEpoch,
});
@@ -544,9 +551,13 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
}
} catch (e) {
if (e is LinkEditNotAllowedError) {
- await _showLinkEditNotAllowedDialog(context);
+ if (context.mounted) {
+ await _showLinkEditNotAllowedDialog(context);
+ }
} else {
- await showGenericErrorDialog(context: context, error: e);
+ if (context.mounted) {
+ await showGenericErrorDialog(context: context, error: e);
+ }
}
rethrow;
}
@@ -581,16 +592,20 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
prop,
);
await dialog?.hide();
- showShortToast(context, AppLocalizations.of(context).albumUpdated);
- if (mounted) {
+ if (context.mounted) {
+ showShortToast(context, AppLocalizations.of(context).albumUpdated);
setState(() {});
}
} catch (e) {
await dialog?.hide();
if (e is LinkEditNotAllowedError) {
- await _showLinkEditNotAllowedDialog(context);
+ if (context.mounted) {
+ await _showLinkEditNotAllowedDialog(context);
+ }
} else {
- await showGenericErrorDialog(context: context, error: e);
+ if (context.mounted) {
+ await showGenericErrorDialog(context: context, error: e);
+ }
}
rethrow;
}
@@ -619,6 +634,7 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
],
);
if (buttonResult?.action == ButtonAction.first) {
+ if (!context.mounted) return;
await Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
diff --git a/mobile/apps/photos/lib/ui/sharing/pickers/layout_picker_page.dart b/mobile/apps/photos/lib/ui/sharing/pickers/layout_picker_page.dart
index 6e1657cb72..b7f040c6e7 100644
--- a/mobile/apps/photos/lib/ui/sharing/pickers/layout_picker_page.dart
+++ b/mobile/apps/photos/lib/ui/sharing/pickers/layout_picker_page.dart
@@ -48,6 +48,7 @@ class LayoutPickerPage extends StatelessWidget {
),
);
} catch (e) {
+ if (!context.mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
}
@@ -132,7 +133,9 @@ class _ItemsWidgetState extends State<ItemsWidget> {
prop,
);
} catch (e) {
- await showGenericErrorDialog(context: context, error: e);
+ if (context.mounted) {
+ await showGenericErrorDialog(context: context, error: e);
+ }
rethrow;
}
}
diff --git a/mobile/apps/photos/lib/ui/sharing/public_link_enabled_actions_widget.dart b/mobile/apps/photos/lib/ui/sharing/public_link_enabled_actions_widget.dart
index 5066c40f5e..42918cfb9f 100644
--- a/mobile/apps/photos/lib/ui/sharing/public_link_enabled_actions_widget.dart
+++ b/mobile/apps/photos/lib/ui/sharing/public_link_enabled_actions_widget.dart
@@ -51,6 +51,7 @@ class PublicLinkEnabledActionsWidget extends StatelessWidget {
showOnlyLoadingState: true,
onTap: () async {
await Clipboard.setData(ClipboardData(text: url));
+ if (!context.mounted) return;
showShortToast(
context,
AppLocalizations.of(context).linkCopiedToClipboard,
diff --git a/mobile/apps/photos/lib/ui/sharing/verify_identity_dialog.dart b/mobile/apps/photos/lib/ui/sharing/verify_identity_dialog.dart
index 086eb34b39..0721be57ed 100644
--- a/mobile/apps/photos/lib/ui/sharing/verify_identity_dialog.dart
+++ b/mobile/apps/photos/lib/ui/sharing/verify_identity_dialog.dart
@@ -164,6 +164,7 @@ class _VerifyIdentifyDialogState extends State<VerifyIdentifyDialog> {
return;
}
await Clipboard.setData(ClipboardData(text: verificationID));
+ if (!context.mounted) return;
// ignore: unawaited_futures
shareText(
widget.self
diff --git a/mobile/apps/photos/lib/ui/social/feed_screen.dart b/mobile/apps/photos/lib/ui/social/feed_screen.dart
index bfa73d5355..aec6001440 100644
--- a/mobile/apps/photos/lib/ui/social/feed_screen.dart
+++ b/mobile/apps/photos/lib/ui/social/feed_screen.dart
@@ -488,6 +488,7 @@ class _FeedScreenState extends State<FeedScreen> {
final targetContext = _navigationTargetItemKey.currentContext;
if (targetContext != null) {
+ if (!targetContext.mounted) return false;
await Scrollable.ensureVisible(
targetContext,
alignment: 0.1,
diff --git a/mobile/apps/photos/lib/ui/tabs/home_widget.dart b/mobile/apps/photos/lib/ui/tabs/home_widget.dart
index 74fe18b184..a0de247725 100644
--- a/mobile/apps/photos/lib/ui/tabs/home_widget.dart
+++ b/mobile/apps/photos/lib/ui/tabs/home_widget.dart
@@ -282,6 +282,7 @@ class _HomeWidgetState extends State<HomeWidget> {
updateService.shouldShowUpdateNotification().then((value) {
Future.delayed(Duration.zero, () {
if (value) {
+ if (!mounted) return;
showDialog(
useRootNavigator: false,
context: context,
@@ -434,6 +435,7 @@ class _HomeWidgetState extends State<HomeWidget> {
publicUrl.opsLimit!,
);
+ if (!mounted) return;
unawaited(
CollectionsService.instance
.verifyPublicCollectionPassword(
@@ -445,6 +447,7 @@ class _HomeWidgetState extends State<HomeWidget> {
if (result) {
await dialog.show();
+ if (!mounted) return;
final List<EnteFile> sharedFiles = await _diffFetcher
.getPublicFiles(
context,
@@ -452,8 +455,10 @@ class _HomeWidgetState extends State<HomeWidget> {
collection.pubMagicMetadata.asc ?? false,
);
await dialog.hide();
+ if (!mounted) return;
Navigator.of(context).pop();
+ if (!mounted) return;
await routeToPage(
context,
SharedPublicCollectionPage(
@@ -467,6 +472,7 @@ class _HomeWidgetState extends State<HomeWidget> {
);
} catch (e, s) {
_logger.severe("Failed to decrypt password for album", e, s);
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: e);
return;
}
@@ -475,6 +481,7 @@ class _HomeWidgetState extends State<HomeWidget> {
} else {
await dialog.show();
+ if (!mounted) return;
final List<EnteFile> sharedFiles = await _diffFetcher.getPublicFiles(
context,
collection.id,
@@ -482,6 +489,7 @@ class _HomeWidgetState extends State<HomeWidget> {
);
await dialog.hide();
+ if (!mounted) return;
await routeToPage(
context,
SharedPublicCollectionPage(
@@ -491,6 +499,7 @@ class _HomeWidgetState extends State<HomeWidget> {
),
);
if (sharedFiles.length == 1) {
+ if (!mounted) return;
await routeToPage(
context,
DetailPage(
@@ -1029,6 +1038,7 @@ class _HomeWidgetState extends State<HomeWidget> {
_shouldRenderCreateCollectionSheet = false;
ReceiveSharingIntent.instance.reset();
Future.delayed(const Duration(milliseconds: 10), () {
+ if (!context.mounted) return;
showCollectionActionSheet(
context,
sharedFiles: _sharedFiles,
@@ -1180,6 +1190,7 @@ class _HomeWidgetState extends State<HomeWidget> {
// but keep in mind it could be `null`.
if (initialLink != null) {
_logger.info("Initial link received: host ${initialLink.host}");
+ if (!mounted) return false;
_getCredentials(context, initialLink);
return true;
} else {
@@ -1195,6 +1206,7 @@ class _HomeWidgetState extends State<HomeWidget> {
_authDeepLinkSubscription = appLinks.uriLinkStream.listen(
(link) {
_logger.info("Link received: host ${link.host}");
+ if (!mounted) return;
_getCredentials(context, link);
},
onError: (err) {
@@ -1235,6 +1247,7 @@ class _HomeWidgetState extends State<HomeWidget> {
updateService.hideChangeLog().ignore();
return;
}
+ if (!context.mounted) return;
final sheetAction = await showBottomSheetComponent<ChangeLogPageAction>(
context: context,
builder: (context) => const ChangeLogPage(),
@@ -1245,6 +1258,7 @@ class _HomeWidgetState extends State<HomeWidget> {
return;
}
if (sheetAction == ChangeLogPageAction.openReferrals) {
+ if (!context.mounted) return;
await routeToPage(context, const ReferralScreen());
}
} finally {
diff --git a/mobile/apps/photos/lib/ui/tabs/shared/all_links_page.dart b/mobile/apps/photos/lib/ui/tabs/shared/all_links_page.dart
index 10e2eb1b30..20c20cc3a8 100644
--- a/mobile/apps/photos/lib/ui/tabs/shared/all_links_page.dart
+++ b/mobile/apps/photos/lib/ui/tabs/shared/all_links_page.dart
@@ -112,6 +112,7 @@ class _AllLinksPageState extends State<AllLinksPage> {
],
);
if (result?.action == ButtonAction.error && context.mounted) {
+ if (!mounted) return;
await showGenericErrorBottomSheet(
context: context,
error: result?.exception,
diff --git a/mobile/apps/photos/lib/ui/tools/debug/app_storage_viewer.dart b/mobile/apps/photos/lib/ui/tools/debug/app_storage_viewer.dart
index 2cc9d51ec2..74669a0eb5 100644
--- a/mobile/apps/photos/lib/ui/tools/debug/app_storage_viewer.dart
+++ b/mobile/apps/photos/lib/ui/tools/debug/app_storage_viewer.dart
@@ -58,6 +58,7 @@ class _AppStorageViewerState extends State<AppStorageViewer> {
appTemporaryDirectory.path + "/" + DefaultCacheManager.key;
final videoCachePath =
appTemporaryDirectory.path + "/" + VideoCacheManager.key;
+ if (!mounted) return;
paths.addAll([
PathStorageItem.name(
imageCachePath,
diff --git a/mobile/apps/photos/lib/ui/tools/deduplicate_page.dart b/mobile/apps/photos/lib/ui/tools/deduplicate_page.dart
index 746cfbe6a2..fa31f91fa3 100644
--- a/mobile/apps/photos/lib/ui/tools/deduplicate_page.dart
+++ b/mobile/apps/photos/lib/ui/tools/deduplicate_page.dart
@@ -232,6 +232,7 @@ class _DeduplicatePageState extends State<DeduplicatePage> {
await deleteDuplicates(totalSize);
} catch (e) {
log("Failed to delete duplicates", error: e);
+ if (!mounted) return;
showGenericErrorDialog(
context: context,
error: e,
@@ -301,8 +302,10 @@ class _DeduplicatePageState extends State<DeduplicatePage> {
}
_deleteProgress.value = "";
if (filesToDelele.isNotEmpty) {
+ if (!mounted) return;
await deleteFilesFromRemoteOnly(context, filesToDelele);
Bus.instance.fire(UserDetailsChangedEvent());
+ if (!mounted) return;
Navigator.of(
context,
).pop(DeduplicationResult(filesToDelele.length, totalSize));
diff --git a/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_page.dart b/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_page.dart
index 59a4ab1d78..b774d12000 100644
--- a/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_page.dart
+++ b/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_page.dart
@@ -201,6 +201,7 @@ class _ImageEditorPageState extends State<ImageEditorPage> {
body: AppLocalizations.of(context).doYouWantToDiscardTheEditsYouHaveMade,
actionSheetType: ActionSheetType.defaultActionSheet,
);
+ if (!context.mounted) return;
if (actionResult?.action != null &&
actionResult!.action == ButtonAction.first) {
replacePage(context, DetailPage(widget.detailPageConfig));
diff --git a/mobile/apps/photos/lib/ui/tools/editor/video_editor_page.dart b/mobile/apps/photos/lib/ui/tools/editor/video_editor_page.dart
index 89b1ee6077..f44807ecb1 100644
--- a/mobile/apps/photos/lib/ui/tools/editor/video_editor_page.dart
+++ b/mobile/apps/photos/lib/ui/tools/editor/video_editor_page.dart
@@ -75,6 +75,7 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
// First determine rotation correction for Android
_doRotationCorrectionIfAndroid().then((_) {
// Then initialize the controller
+ if (!mounted) return;
_controller = VideoEditorController.file(
widget.ioFile,
minDuration: const Duration(seconds: 1),
@@ -111,6 +112,7 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
})
.catchError((error) {
// handle minimum duration bigger than video duration error
+ if (!mounted) return;
Navigator.pop(context);
}, test: (e) => e is VideoMinDurationError);
});
@@ -310,6 +312,7 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
Navigator.of(dialogKey.currentContext!).pop();
}
+ if (!mounted) return;
showShortToast(context, AppLocalizations.of(context).somethingWentWrong);
}
}
@@ -590,6 +593,7 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
SyncService.instance.sync().ignore();
+ if (!mounted) return;
showShortToast(context, AppLocalizations.of(context).editsSaved);
final files = List<EnteFile>.of(widget.detailPageConfig.files);
@@ -613,6 +617,7 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
}
Navigator.of(dialogKey.currentContext!).pop('dialog');
+ if (!mounted) return;
replacePage(
context,
DetailPage(
diff --git a/mobile/apps/photos/lib/ui/tools/free_space_page.dart b/mobile/apps/photos/lib/ui/tools/free_space_page.dart
index 9fa1cd926a..d3aadac9f0 100644
--- a/mobile/apps/photos/lib/ui/tools/free_space_page.dart
+++ b/mobile/apps/photos/lib/ui/tools/free_space_page.dart
@@ -169,6 +169,7 @@ class _FreeSpacePageState extends State<FreeSpacePage> {
bool isSuccess = await deleteLocalFiles(context, status.localIDs);
if (isSuccess == false) {
+ if (!mounted) return;
isSuccess = await deleteLocalFilesAfterRemovingAlreadyDeletedIDs(
context,
status.localIDs,
@@ -176,14 +177,17 @@ class _FreeSpacePageState extends State<FreeSpacePage> {
}
if (isSuccess == false && Platform.isAndroid) {
+ if (!mounted) return;
isSuccess = await retryFreeUpSpaceAfterRemovingAssetsNonExistingInDisk(
context,
);
}
if (isSuccess) {
+ if (!mounted) return;
Navigator.of(context).pop(true);
} else {
+ if (!mounted) return;
showToast(context, AppLocalizations.of(context).couldNotFreeUpSpace);
}
}
diff --git a/mobile/apps/photos/lib/ui/tools/similar_images_page.dart b/mobile/apps/photos/lib/ui/tools/similar_images_page.dart
index ae215a3f2b..73aa5c52ec 100644
--- a/mobile/apps/photos/lib/ui/tools/similar_images_page.dart
+++ b/mobile/apps/photos/lib/ui/tools/similar_images_page.dart
@@ -676,9 +676,11 @@ class _SimilarImagesPageState extends State<SimilarImagesPage>
_logger.severe("Failed to get similar files", e, s);
if (_isDisposed) return;
if (flagService.internalUser) {
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
if (_isDisposed) return;
+ if (!mounted) return;
Navigator.of(context).pop();
}
}
@@ -978,6 +980,7 @@ class _SimilarImagesPageState extends State<SimilarImagesPage>
);
} catch (e, s) {
_logger.severe("Failed to delete files", e, s);
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
},
@@ -1149,6 +1152,7 @@ class _SimilarImagesPageState extends State<SimilarImagesPage>
}
});
}
+ if (!mounted) return;
await deleteFilesFromRemoteOnly(context, allDeleteFiles.toList());
// Show congratulations popup
diff --git a/mobile/apps/photos/lib/ui/viewer/actions/album_selection_action_widget.dart b/mobile/apps/photos/lib/ui/viewer/actions/album_selection_action_widget.dart
index 0a084648ae..84032573e1 100644
--- a/mobile/apps/photos/lib/ui/viewer/actions/album_selection_action_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/actions/album_selection_action_widget.dart
@@ -384,6 +384,7 @@ class _AlbumSelectionActionWidgetState
? visibleVisibility
: hiddenVisibility;
+ if (!mounted) return;
await changeCollectionVisibility(
context,
collection: collection,
@@ -393,6 +394,7 @@ class _AlbumSelectionActionWidgetState
showProgressDialog: false,
);
}
+ if (!mounted) return;
showShortToast(
context,
isUnhiding
@@ -401,6 +403,7 @@ class _AlbumSelectionActionWidgetState
);
} catch (e, s) {
_logger.warning("failed to change visibility", e, s);
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: e);
} finally {
await dialog.hide();
@@ -449,6 +452,7 @@ class _AlbumSelectionActionWidgetState
? visibleVisibility
: archiveVisibility;
+ if (!mounted) return;
await changeCollectionVisibility(
context,
collection: collection,
@@ -466,6 +470,7 @@ class _AlbumSelectionActionWidgetState
? visibleVisibility
: archiveVisibility;
+ if (!mounted) return;
await changeCollectionVisibility(
context,
collection: collection,
@@ -475,6 +480,7 @@ class _AlbumSelectionActionWidgetState
);
}
}
+ if (!mounted) return;
showShortToast(
context,
isUnarchiving
@@ -483,6 +489,7 @@ class _AlbumSelectionActionWidgetState
);
} catch (e, s) {
_logger.warning("failed to change archive state", e, s);
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: e);
} finally {
await dialog.hide();
diff --git a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart
index 53700db4c1..378a297c03 100644
--- a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart
@@ -657,6 +657,7 @@ class _FileSelectionActionsWidgetState
);
} catch (e, s) {
_logger.warning("Failed to reject delete suggestions", e, s);
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
}
@@ -788,6 +789,7 @@ class _FileSelectionActionsWidgetState
relevantFiles: addedFiles,
),
);
+ if (!mounted) return;
showToast(
context,
AppLocalizations.of(context).addedFilesToPerson(
@@ -803,6 +805,7 @@ class _FileSelectionActionsWidgetState
}
final alreadyCount = result.alreadyAssignedFileIds.length;
if (alreadyCount > 0) {
+ if (!mounted) return;
showShortToast(
context,
AppLocalizations.of(context).filesAlreadyLinkedToPerson(
@@ -815,7 +818,9 @@ class _FileSelectionActionsWidgetState
Future<void> _onGuestViewClick() async {
final List<EnteFile> selectedFiles = widget.selectedFiles.files.toList();
- if (await LocalAuthentication().isDeviceSupported()) {
+ final isDeviceSupported = await LocalAuthentication().isDeviceSupported();
+ if (!mounted) return;
+ if (isDeviceSupported) {
final page = DetailPage(
DetailPageConfiguration(
selectedFiles,
@@ -825,6 +830,7 @@ class _FileSelectionActionsWidgetState
),
);
await localSettings.setOnGuestView(true);
+ if (!mounted) return;
routeToPage(context, page, forceCustomPageRoute: true).ignore();
WidgetsBinding.instance.addPostFrameCallback((_) {
Bus.instance.fire(GuestViewEvent(true, false));
@@ -836,6 +842,7 @@ class _FileSelectionActionsWidgetState
AppLocalizations.of(context).guestViewEnablePreSteps,
);
}
+ if (!mounted) return;
widget.selectedFiles.clearAll();
}
@@ -907,19 +914,27 @@ class _FileSelectionActionsWidgetState
isDismissible: true,
);
await dialog.show();
+ if (!mounted) {
+ await dialog.hide();
+ return;
+ }
_cachedCollectionForSharedLink ??= await collectionActions
.createSharedCollectionLink(context, split.ownedByCurrentUser);
+ if (!mounted) {
+ await dialog.hide();
+ return;
+ }
if (_cachedCollectionForSharedLink == null) {
await dialog.hide();
return;
}
await dialog.hide();
+ if (!mounted) return;
await _sendLink();
+ if (!mounted) return;
widget.selectedFiles.clearAll();
- if (mounted) {
- setState(() => {});
- }
+ setState(() => {});
}
Future<void> _setPersonCover() async {
@@ -1079,7 +1094,7 @@ class _FileSelectionActionsWidgetState
try {
await deleteFilesOnDeviceOnly(context, filesToDelete);
} catch (e) {
- if (context.mounted) {
+ if (mounted) {
await showGenericErrorDialog(context: context, error: e);
}
rethrow;
@@ -1113,6 +1128,7 @@ class _FileSelectionActionsWidgetState
final existingLocalFolderNames = await Future.wait(
files.map((file) => getExistingLocalFolderNameForDownloadSkipToast(file)),
);
+ if (!mounted) return;
final filesToDownload = <EnteFile>[];
final skippedFiles = <EnteFile>[];
diff --git a/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dart b/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dart
index 57c5c40122..0ee875095e 100644
--- a/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dart
@@ -325,6 +325,7 @@ class _PeopleSelectionActionWidgetState
? null
: person.data.assigned.first.id;
+ if (!mounted) return;
await routeToPage(
context,
SaveOrEditPerson(clusterID, person: person, isEditing: true),
@@ -341,6 +342,7 @@ class _PeopleSelectionActionWidgetState
if (person == null) return;
if (person.data.assigned.isEmpty) return;
+ if (!mounted) return;
await routeToPage(context, PersonReviewClusterSuggestion(person));
widget.selectedPeople.clearAll();
}
@@ -349,6 +351,7 @@ class _PeopleSelectionActionWidgetState
final personMap = await personEntitiesMapFuture;
final selectedPersonIds = _getSelectedPersonIds(personMap);
if (selectedPersonIds.isEmpty) return;
+ if (!mounted) return;
showCollectionActionSheet(
context,
selectedPeople: selectedPersonIds,
@@ -409,6 +412,7 @@ class _PeopleSelectionActionWidgetState
final person = personMap[personID];
if (person == null) return;
+ if (!mounted) return;
await showChoiceDialog(
context,
title: AppLocalizations.of(context).areYouSureYouWantToResetThisPerson,
@@ -432,6 +436,7 @@ class _PeopleSelectionActionWidgetState
if (selectedPersonIds.isEmpty && selectedClusterIds.isEmpty) return;
final multiple = (selectedPersonIds.length + selectedClusterIds.length) > 1;
+ if (!mounted) return;
final result = await showChoiceDialog(
context,
title: multiple
@@ -548,6 +553,7 @@ class _PeopleSelectionActionWidgetState
}
final multiple = ignoredSelectedPersonIds.length > 1;
+ if (!mounted) return;
await showChoiceDialog(
context,
title: multiple
diff --git a/mobile/apps/photos/lib/ui/viewer/actions/suggest_delete_sheet.dart b/mobile/apps/photos/lib/ui/viewer/actions/suggest_delete_sheet.dart
index b010334967..4cf2adb40e 100644
--- a/mobile/apps/photos/lib/ui/viewer/actions/suggest_delete_sheet.dart
+++ b/mobile/apps/photos/lib/ui/viewer/actions/suggest_delete_sheet.dart
@@ -46,6 +46,7 @@ Future<bool> showSuggestDeleteSheet({
isInAlert: true,
onTap: () async {
await onConfirm();
+ if (!context.mounted) return;
showShortToast(context, l10n.deleteSuggestionSent);
},
),
@@ -61,6 +62,7 @@ Future<bool> showSuggestDeleteSheet({
);
if (actionResult?.action == ButtonAction.error) {
+ if (!context.mounted) return false;
await showGenericErrorDialog(
context: context,
error:
diff --git a/mobile/apps/photos/lib/ui/viewer/date/edit_date_sheet.dart b/mobile/apps/photos/lib/ui/viewer/date/edit_date_sheet.dart
index 2f4a0e822d..13a2d299ac 100644
--- a/mobile/apps/photos/lib/ui/viewer/date/edit_date_sheet.dart
+++ b/mobile/apps/photos/lib/ui/viewer/date/edit_date_sheet.dart
@@ -179,6 +179,7 @@ class _EditDateSheetState extends State<EditDateSheet> {
selectedDate,
selectSingleDate ? null : startDate,
);
+ if (!context.mounted) return;
Navigator.of(context).pop(newDate);
},
),
diff --git a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
index 6b1d9c29af..3d0414e53a 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
@@ -400,6 +400,7 @@ class _BodyState extends State<_Body> {
},
playbackCallback: (shouldEnable, reason) {
Future.delayed(Duration.zero, () {
+ if (!context.mounted) return;
InheritedDetailPageState.of(
context,
).requestFullScreen(shouldEnable: shouldEnable, reason: reason);
@@ -517,6 +518,7 @@ class _BodyState extends State<_Body> {
try {
final ioFile = await getFile(file);
if (ioFile == null) {
+ if (!mounted) return;
showShortToast(
context,
AppLocalizations.of(context).failedToFetchOriginalForEdit,
@@ -526,6 +528,7 @@ class _BodyState extends State<_Body> {
}
if (file.fileType == FileType.video) {
await dialog.hide();
+ if (!mounted) return;
replacePage(
context,
VideoEditorPage(
@@ -543,8 +546,10 @@ class _BodyState extends State<_Body> {
ioFile,
cacheRawData: true,
);
+ if (!mounted) return;
await precacheImage(imageProvider, context);
await dialog.hide();
+ if (!mounted) return;
replacePage(
context,
ImageEditorPage(
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
index 0f27f71e40..bcedf5f0ae 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
@@ -607,6 +607,7 @@ class FileAppBarState extends State<FileAppBar> {
}
} catch (e, s) {
_logger.severe("failed to update file visibility", e, s);
+ if (!context.mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
}
@@ -671,6 +672,7 @@ class FileAppBarState extends State<FileAppBar> {
return;
}
+ if (!mounted) return;
final dialog = createProgressDialog(
context,
AppLocalizations.of(context).downloading,
@@ -711,6 +713,7 @@ class FileAppBarState extends State<FileAppBar> {
isDismissible: true,
);
await dialog.show();
+ if (!mounted) return;
final Collection? sharedLinkCollection = await CollectionActions(
CollectionsService.instance,
).createSharedCollectionLink(context, [file]);
@@ -723,6 +726,7 @@ class FileAppBarState extends State<FileAppBar> {
);
await dialog.hide();
unawaited(Clipboard.setData(ClipboardData(text: url)));
+ if (!mounted) return;
await shareLinkWithDescription(url, context: context);
}
@@ -740,6 +744,7 @@ class FileAppBarState extends State<FileAppBar> {
final m = MediaExtension();
final bool result = await m.setAs("file://${fileToSave.path}", "image/*");
if (result == false) {
+ if (!mounted) return;
showShortToast(
context,
AppLocalizations.of(context).somethingWentWrong,
@@ -749,6 +754,7 @@ class FileAppBarState extends State<FileAppBar> {
} catch (e) {
await dialog.hide();
_logger.severe("Failed to use as", e);
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
}
@@ -758,6 +764,7 @@ class FileAppBarState extends State<FileAppBar> {
Bus.instance.fire(GuestViewEvent(true, true));
await localSettings.setOnGuestView(true);
} else {
+ if (!mounted) return;
await showErrorDialog(
context,
AppLocalizations.of(context).noSystemLockFound,
@@ -810,10 +817,12 @@ class FileAppBarState extends State<FileAppBar> {
if (!wasAdded) {
// File was already in queue
+ if (!mounted) return;
showToast(context, AppLocalizations.of(context).videoAlreadyInQueue);
return;
}
+ if (!mounted) return;
showToast(context, AppLocalizations.of(context).addedToQueue);
if (mounted) {
@@ -823,6 +832,7 @@ class FileAppBarState extends State<FileAppBar> {
}
} catch (e, s) {
_logger.severe("Failed to $streamType video stream", e, s);
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
}
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart b/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart
index b258013dd8..d1dce30117 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart
@@ -350,6 +350,7 @@ class FileBottomBarState extends State<FileBottomBar> {
final trashedFile = <TrashFile>[];
trashedFile.add(widget.file as TrashFile);
if (await deleteFromTrash(context, trashedFile) == true) {
+ if (!mounted) return;
Navigator.pop(context);
}
},
@@ -434,6 +435,7 @@ class FileBottomBarState extends State<FileBottomBar> {
}
} else {
// Multiple shared collections: show selector bottom sheet
+ if (!mounted) return;
await showLikeCollectionSelectorSheet(
context,
fileID: file.uploadedFileID!,
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_caption_widget.dart b/mobile/apps/photos/lib/ui/viewer/file/file_caption_widget.dart
index ba60bd7be6..19f18eae04 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_caption_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_caption_widget.dart
@@ -155,6 +155,7 @@ class _FileCaptionWidgetState extends State<FileCaptionWidget> {
).then((isSuccess) => _onEditFileFinish(isSuccess));
if (isSuccesful) {
if (mounted) {
+ if (!context.mounted) return;
Navigator.pop(context);
}
}
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_details_widget.dart b/mobile/apps/photos/lib/ui/viewer/file/file_details_widget.dart
index 42b6544f0c..13d76f53c4 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_details_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_details_widget.dart
@@ -130,12 +130,12 @@ class _FileDetailsWidgetState extends State<FileDetailsWidget> {
final File? originFile = await getFile(widget.file, isOrigin: true);
if (originFile == null) return;
final properties = await getVideoPropsAsync(originFile);
+ if (!mounted) return;
_videoMetadataNotifier.value = properties;
if (kDebugMode) {
log("videoCustomProps ${properties.toString()}");
log("PropData ${properties?.propData.toString()}");
}
- if (!mounted) return;
setState(() {});
}
diff --git a/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit.dart b/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit.dart
index e73d12dfe9..408b24299c 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit.dart
@@ -314,6 +314,7 @@ class _VideoWidgetMediaKitState extends State<VideoWidgetMediaKit>
}
})
.onError((error, stackTrace) {
+ if (!mounted) return;
showErrorDialog(
context,
AppLocalizations.of(context).error,
diff --git a/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart b/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart
index 61143a80c9..65532477a7 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart
@@ -174,6 +174,7 @@ class _ZoomableImageState extends State<ZoomableImage> {
_zoomStreamSubscription = _photoViewController.outputStateStream.listen((
value,
) {
+ if (!mounted) return;
final state = InheritedDetailPageState.maybeOf(context);
if (value.scale == null) return;
if (!_isZooming) {
@@ -465,6 +466,7 @@ class _ZoomableImageState extends State<ZoomableImage> {
quality: 100,
).then((cachedThumbnail) {
if (cachedThumbnail != null) {
+ if (!context.mounted) return;
_onLargeThumbnailLoaded(Image.memory(cachedThumbnail).image, context);
}
});
diff --git a/mobile/apps/photos/lib/ui/viewer/file/zoomable_live_image_new.dart b/mobile/apps/photos/lib/ui/viewer/file/zoomable_live_image_new.dart
index 3453baa495..6b9cdb6944 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/zoomable_live_image_new.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/zoomable_live_image_new.dart
@@ -226,6 +226,7 @@ class _ZoomableLiveImageNewState extends State<ZoomableLiveImageNew>
if (videoFile != null && videoFile.existsSync()) {
await _setVideoController(videoFile.path);
} else if (_enteFile.isLivePhoto) {
+ if (!mounted) return;
showShortToast(context, AppLocalizations.of(context).downloadFailed);
}
} finally {
@@ -236,6 +237,7 @@ class _ZoomableLiveImageNewState extends State<ZoomableLiveImageNew>
Future<File?> _getLivePhotoVideo() async {
if (_enteFile.isRemoteOnlyFile &&
!(await isFileCached(_enteFile, liveVideo: true))) {
+ if (!mounted) return null;
showShortToast(context, AppLocalizations.of(context).downloading);
}
@@ -263,6 +265,7 @@ class _ZoomableLiveImageNewState extends State<ZoomableLiveImageNew>
Future<File?> _getMotionPhotoVideo() async {
if (_enteFile.isRemoteOnlyFile && !(await isFileCached(_enteFile))) {
+ if (!mounted) return null;
showShortToast(context, AppLocalizations.of(context).downloading);
}
diff --git a/mobile/apps/photos/lib/ui/viewer/file_details/albums_item_widget.dart b/mobile/apps/photos/lib/ui/viewer/file_details/albums_item_widget.dart
index 79f4cd8acc..e1752039bf 100644
--- a/mobile/apps/photos/lib/ui/viewer/file_details/albums_item_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file_details/albums_item_widget.dart
@@ -79,6 +79,7 @@ class AlbumsItemWidget extends StatelessWidget {
for (var collectionID in collectionIDs) {
final c = CollectionsService.instance.getCollectionByID(collectionID);
collections.add(c!);
+ if (!context.mounted) return const [];
chipButtons.add(
ChipButtonWidget(
c.isHidden() ? AppLocalizations.of(context).hidden : c.displayName,
diff --git a/mobile/apps/photos/lib/ui/viewer/file_details/favorite_widget.dart b/mobile/apps/photos/lib/ui/viewer/file_details/favorite_widget.dart
index e34bcd9b4d..124f1a8c36 100644
--- a/mobile/apps/photos/lib/ui/viewer/file_details/favorite_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file_details/favorite_widget.dart
@@ -120,6 +120,7 @@ class _FavoriteWidgetState extends State<FavoriteWidget> {
} catch (e, s) {
_logger.severe("Failed to add file to favorites", e, s);
hasError = true;
+ if (!mounted) return;
showToast(
context,
AppLocalizations.of(context).sorryCouldNotAddToFavorites,
@@ -138,6 +139,7 @@ class _FavoriteWidgetState extends State<FavoriteWidget> {
} catch (e, s) {
_logger.severe("Failed to remove file from favorites", e, s);
hasError = true;
+ if (!mounted) return;
showToast(
context,
AppLocalizations.of(context).sorryCouldNotRemoveFromFavorites,
diff --git a/mobile/apps/photos/lib/ui/viewer/file_details/location_tags_widget.dart b/mobile/apps/photos/lib/ui/viewer/file_details/location_tags_widget.dart
index 62f2f41a96..1314ddac96 100644
--- a/mobile/apps/photos/lib/ui/viewer/file_details/location_tags_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file_details/location_tags_widget.dart
@@ -115,6 +115,7 @@ class _LocationTagsWidgetState extends State<LocationTagsWidget> {
onTap = null;
});
}
+ if (!mounted) return const [];
return [
ChipButtonWidget(
AppLocalizations.of(context).addLocation,
@@ -295,10 +296,12 @@ class _InfoMapState extends State<InfoMap> {
onTap: () async {
try {
await setMapEnabled(true);
+ if (!mounted) return;
setState(() {
_hasEnabledMap = true;
});
} catch (e) {
+ if (!context.mounted) return;
showShortToast(
context,
AppLocalizations.of(
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/cleanup_hidden_from_device_page.dart b/mobile/apps/photos/lib/ui/viewer/gallery/cleanup_hidden_from_device_page.dart
index f98dbd7895..3a4eb4e8fd 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/cleanup_hidden_from_device_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/cleanup_hidden_from_device_page.dart
@@ -164,7 +164,9 @@ class _CleanupHiddenFromDevicePageState
final allFiles = await CollectionsService.instance.getHiddenFilesOnDevice();
if (allFiles.isEmpty) return;
+ if (!mounted) return;
final l10n = AppLocalizations.of(context);
+ if (!mounted) return;
final actionResult = await showActionSheet(
context: context,
title: l10n.deleteFromDeviceQuestion,
@@ -182,6 +184,7 @@ class _CleanupHiddenFromDevicePageState
await deleteFilesOnDeviceOnly(context, allFiles);
} catch (e) {
if (context.mounted) {
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
rethrow;
@@ -204,6 +207,7 @@ class _CleanupHiddenFromDevicePageState
if (actionResult?.action == ButtonAction.first) {
widget.onCleanupComplete?.call();
if (context.mounted) {
+ if (!mounted) return;
Navigator.of(context).pop();
}
}
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/empty_album_state.dart b/mobile/apps/photos/lib/ui/viewer/gallery/empty_album_state.dart
index a2b249e5b1..215bfb6dd2 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/empty_album_state.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/empty_album_state.dart
@@ -49,6 +49,7 @@ class EmptyAlbumState extends StatelessWidget {
try {
await showAddPhotosSheet(context, c);
} catch (e) {
+ if (!context.mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
},
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
index d7479a5bae..051116b9e5 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
@@ -333,6 +333,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
},
);
if (result is Exception) {
+ if (!context.mounted) return null;
await showGenericErrorDialog(context: context, error: result);
}
}
@@ -367,11 +368,13 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
);
if (actionResult?.action != null && mounted) {
if (actionResult!.action == ButtonAction.error) {
+ if (!context.mounted) return null;
await showGenericErrorDialog(
context: context,
error: actionResult.exception,
);
} else if (actionResult.action == ButtonAction.first) {
+ if (!context.mounted) return null;
Navigator.of(context).pop();
}
}
@@ -394,18 +397,21 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
);
} catch (e) {
await dialog.hide();
+ if (!context.mounted) return null;
unawaited(showGenericErrorDialog(context: context, error: e));
return;
}
await dialog.hide();
if (status.localIDs.isEmpty) {
+ if (!context.mounted) return null;
await showErrorDialog(
context,
AppLocalizations.of(context).allClear,
AppLocalizations.of(context).youveNoFilesInThisAlbumThatCanBeDeleted,
);
} else {
+ if (!context.mounted) return null;
final bool? result = await routeToPage(
context,
FreeSpacePage(status, clearSpaceForFolder: true),
@@ -900,6 +906,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
);
} catch (e, s) {
_logger.severe("Failed to download album", e, s);
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
return;
@@ -920,6 +927,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
}
} catch (e, s) {
_logger.severe("Failed to download album", e, s);
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
await dialog.hide();
@@ -937,8 +945,10 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
await locationService.deleteLocationTag(
InheritedLocationScreenState.of(context).locationTagEntity.id,
);
+ if (!mounted) return;
Navigator.of(context).pop();
} catch (e) {
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
}
@@ -953,6 +963,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
);
if (actionResult?.action != null && mounted) {
if (actionResult!.action == ButtonAction.first) {
+ if (!buildContext.mounted) return;
await collectionActions.removeFromUncatIfPresentInOtherAlbum(
widget.collection!,
buildContext,
@@ -967,6 +978,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
widget.collection!,
);
if (coverPhotoID != null) {
+ if (!context.mounted) return;
unawaited(changeCoverPhoto(context, widget.collection!, coverPhotoID));
}
}
@@ -976,6 +988,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
try {
await setMapEnabled(true);
} catch (e) {
+ if (!mounted) return;
showShortToast(
context,
AppLocalizations.of(context).somethingWentWrong,
@@ -983,6 +996,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
return;
}
}
+ if (!mounted) return;
unawaited(
Navigator.of(context).push(
MaterialPageRoute(
@@ -1019,6 +1033,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
],
);
if (sortByAsc != null) {
+ if (!bContext.mounted) return;
unawaited(changeSortOrder(bContext, widget.collection!, sortByAsc));
}
}
@@ -1074,6 +1089,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
}
} catch (e, s) {
_logger.severe("failed to trash collection", e, s);
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
}
@@ -1137,6 +1153,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
);
if (res != null && res.action == ButtonAction.first) {
+ if (!mounted) return;
await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => WebPage(
@@ -1151,6 +1168,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
}
} catch (e, s) {
_logger.severe("Failed to show add photo dialog", e, s);
+ if (!bContext.mounted) return;
await showGenericErrorDialog(context: bContext, error: e);
}
}
@@ -1202,11 +1220,13 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
);
collectionFiles = filesResult.files;
} else {
+ if (!mounted) return;
showToast(context, AppLocalizations.of(context).somethingWentWrong);
return;
}
if (collectionFiles.isEmpty) {
+ if (!mounted) return;
showToast(context, AppLocalizations.of(context).nothingToSeeHere);
return;
}
@@ -1221,11 +1241,13 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
),
);
await localSettings.setOnGuestView(true);
+ if (!mounted) return;
routeToPage(context, page, forceCustomPageRoute: true).ignore();
WidgetsBinding.instance.addPostFrameCallback((_) {
Bus.instance.fire(GuestViewEvent(true, false));
});
} else {
+ if (!mounted) return;
await showErrorDialog(
context,
AppLocalizations.of(context).noSystemLockFound,
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/hierarchical_search_gallery.dart b/mobile/apps/photos/lib/ui/viewer/gallery/hierarchical_search_gallery.dart
index 59455784b5..40544c9bb6 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/hierarchical_search_gallery.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/hierarchical_search_gallery.dart
@@ -71,6 +71,7 @@ class _HierarchicalSearchGalleryState extends State<HierarchicalSearchGallery> {
event.type == EventType.hide) {
for (var updatedFile in event.updatedFiles) {
_filterdFiles.remove(updatedFile);
+ if (!mounted) return;
GalleryFilesState.of(context).galleryFiles.remove(updatedFile);
}
setState(() {});
@@ -109,6 +110,7 @@ class _HierarchicalSearchGalleryState extends State<HierarchicalSearchGallery> {
final filterdFiles = await getFilteredFiles(filters);
_setFilteredFiles(filterdFiles);
+ if (!mounted) return;
await curateFilters(_searchFilterDataProvider!, filterdFiles, context);
_setUnnamedFaceFilter(filters);
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/add_photos_sheet.dart b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/add_photos_sheet.dart
index a2070ab98a..72fb0e0ddf 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/add_photos_sheet.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/add_photos_sheet.dart
@@ -152,6 +152,7 @@ class AddPhotosPhotoWidget extends StatelessWidget {
false,
selectedFiles: selectedFile.toList(),
);
+ if (!context.mounted) return;
Navigator.pop(context, selectedFile);
},
),
@@ -180,6 +181,7 @@ class AddPhotosPhotoWidget extends StatelessWidget {
Future<void> _onPickFromDeviceClicked(BuildContext context) async {
try {
final assetPickerTextDelegate = await _getAssetPickerTextDelegate();
+ if (!context.mounted) return;
final List<AssetEntity>? result = await AssetPicker.pickAssets(
context,
pickerConfig: AssetPickerConfig(
@@ -192,12 +194,14 @@ class AddPhotosPhotoWidget extends StatelessWidget {
);
if (result != null && result.isNotEmpty) {
final ca = CollectionActions(CollectionsService.instance);
+ if (!context.mounted) return;
await ca.addToCollection(
context,
collection.id,
false,
picketAssets: result,
);
+ if (!context.mounted) return;
Navigator.of(context).pop();
}
} catch (e) {
@@ -205,6 +209,7 @@ class AddPhotosPhotoWidget extends StatelessWidget {
final PermissionState ps = await permissionService
.requestPhotoMangerPermissions();
if (ps != PermissionState.authorized && ps != PermissionState.limited) {
+ if (!context.mounted) return;
await showChoiceDialog(
context,
title: context.l10n.grantPermission,
@@ -216,6 +221,7 @@ class AddPhotosPhotoWidget extends StatelessWidget {
},
);
} else {
+ if (!context.mounted) return;
await showErrorDialog(
context,
context.l10n.oops,
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/pick_person_avatar.dart b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/pick_person_avatar.dart
index 8e963ed124..3acb2eef5b 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/pick_person_avatar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/pick_person_avatar.dart
@@ -148,6 +148,7 @@ class PickPersonCoverPhotoWidget extends StatelessWidget {
person: result,
),
);
+ if (!context.mounted) return;
Navigator.pop(context, result);
},
),
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/layout_settings.dart b/mobile/apps/photos/lib/ui/viewer/gallery/layout_settings.dart
index 3b64f2f241..d10b8839e5 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/layout_settings.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/layout_settings.dart
@@ -89,6 +89,7 @@ class _GalleryLayoutSettingsState extends State<GalleryLayoutSettings> {
ForceReloadHomeGalleryEvent("Gallery layout changed"),
);
+ if (!context.mounted) return;
Navigator.pop(context);
},
),
@@ -118,6 +119,7 @@ class _GalleryLayoutSettingsState extends State<GalleryLayoutSettings> {
ForceReloadHomeGalleryEvent("Gallery layout changed"),
);
+ if (!context.mounted) return;
Navigator.pop(context);
},
),
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/shared_public_collection_page.dart b/mobile/apps/photos/lib/ui/viewer/gallery/shared_public_collection_page.dart
index 4a031688e8..bce0f9b216 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/shared_public_collection_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/shared_public_collection_page.dart
@@ -77,6 +77,7 @@ class _SharedPublicCollectionPageState
firstButtonLabel: context.l10n.join,
);
if (result != null && result.action == ButtonAction.first) {
+ if (!mounted) return;
final dialog = createProgressDialog(
context,
context.l10n.pleaseWait,
@@ -84,6 +85,7 @@ class _SharedPublicCollectionPageState
);
await dialog.show();
try {
+ if (!mounted) return;
await RemoteSyncService.instance.joinAndSyncCollection(
context,
widget.c.collection.id,
@@ -92,7 +94,9 @@ class _SharedPublicCollectionPageState
widget.c.collection.id,
);
await dialog.hide();
+ if (!mounted) return;
Navigator.of(context).pop();
+ if (!mounted) return;
await routeToPage(
context,
CollectionPage(CollectionWithThumbnail(c!, null)),
@@ -100,6 +104,7 @@ class _SharedPublicCollectionPageState
} catch (e, s) {
logger.severe("Failed to join public album", e, s);
await dialog.hide();
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
}
@@ -219,6 +224,7 @@ class _SharedPublicCollectionPageState
firstButtonLabel: context.l10n.join,
);
if (result != null && result.action == ButtonAction.first) {
+ if (!mounted) return;
final dialog = createProgressDialog(
context,
AppLocalizations.of(context).pleaseWait,
@@ -226,6 +232,7 @@ class _SharedPublicCollectionPageState
);
await dialog.show();
try {
+ if (!mounted) return;
await RemoteSyncService.instance.joinAndSyncCollection(
context,
widget.c.collection.id,
@@ -234,7 +241,9 @@ class _SharedPublicCollectionPageState
widget.c.collection.id,
);
await dialog.hide();
+ if (!mounted) return;
Navigator.of(context).pop();
+ if (!mounted) return;
await routeToPage(
context,
CollectionPage(CollectionWithThumbnail(c!, null)),
@@ -242,6 +251,7 @@ class _SharedPublicCollectionPageState
} catch (e, s) {
logger.severe("Failed to join collection", e, s);
await dialog.hide();
+ if (!mounted) return;
showToast(context, AppLocalizations.of(context).somethingWentWrong);
}
}
diff --git a/mobile/apps/photos/lib/ui/viewer/location/add_location_sheet.dart b/mobile/apps/photos/lib/ui/viewer/location/add_location_sheet.dart
index ad48e0f6de..054cbf2b77 100644
--- a/mobile/apps/photos/lib/ui/viewer/location/add_location_sheet.dart
+++ b/mobile/apps/photos/lib/ui/viewer/location/add_location_sheet.dart
@@ -262,6 +262,7 @@ class _AddLocationSheetState extends State<AddLocationSheet> {
coordinates,
radius,
);
+ if (!mounted) return;
Navigator.pop(context);
}
diff --git a/mobile/apps/photos/lib/ui/viewer/location/edit_center_point_tile_widget.dart b/mobile/apps/photos/lib/ui/viewer/location/edit_center_point_tile_widget.dart
index e669e48c66..5d7b5d12e6 100644
--- a/mobile/apps/photos/lib/ui/viewer/location/edit_center_point_tile_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/location/edit_center_point_tile_widget.dart
@@ -58,6 +58,7 @@ class EditCenterPointTileWidget extends StatelessWidget {
).locationTagEntity!.item.name,
);
if (centerPoint != null) {
+ if (!context.mounted) return;
InheritedLocationTagData.of(
context,
).updateCenterPoint(centerPoint);
diff --git a/mobile/apps/photos/lib/ui/viewer/location/edit_location_sheet.dart b/mobile/apps/photos/lib/ui/viewer/location/edit_location_sheet.dart
index e43a7275ab..c4e18ee3f3 100644
--- a/mobile/apps/photos/lib/ui/viewer/location/edit_location_sheet.dart
+++ b/mobile/apps/photos/lib/ui/viewer/location/edit_location_sheet.dart
@@ -251,6 +251,7 @@ class _EditLocationSheetState extends State<EditLocationSheet> {
newName: _textEditingController.text.trim(),
newCenterPoint: InheritedLocationTagData.of(context).centerPoint,
);
+ if (!mounted) return;
Navigator.of(context).pop();
}
diff --git a/mobile/apps/photos/lib/ui/viewer/location/radius_picker_widget.dart b/mobile/apps/photos/lib/ui/viewer/location/radius_picker_widget.dart
index 0fef8cff28..f352fc520b 100644
--- a/mobile/apps/photos/lib/ui/viewer/location/radius_picker_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/location/radius_picker_widget.dart
@@ -201,6 +201,7 @@ class _RadiusPickerWidgetState extends State<RadiusPickerWidget> {
alignMessage: Alignment.centerRight,
);
if (result is Exception) {
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: result);
_logger.severe("Failed to create custom radius", result);
}
diff --git a/mobile/apps/photos/lib/ui/viewer/location/update_location_data_widget.dart b/mobile/apps/photos/lib/ui/viewer/location/update_location_data_widget.dart
index c4cb775cfc..62f547aa3e 100644
--- a/mobile/apps/photos/lib/ui/viewer/location/update_location_data_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/location/update_location_data_widget.dart
@@ -160,6 +160,7 @@ class _UpdateLocationDataWidgetState extends State<UpdateLocationDataWidget> {
selectedLocation.value!,
context,
);
+ if (!context.mounted) return;
Navigator.of(context).pop();
},
heroTag: 'add-location',
diff --git a/mobile/apps/photos/lib/ui/viewer/people/cluster_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/people/cluster_app_bar.dart
index e447cd1b6e..a877c7a061 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/cluster_app_bar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/cluster_app_bar.dart
@@ -204,6 +204,7 @@ class _AppBarWidgetState extends State<ClusterAppBar> {
return;
}
+ if (!context.mounted) return;
Navigator.of(context).pop(ClusterPageResult.ignoredPerson);
}
@@ -262,17 +263,20 @@ class _AppBarWidgetState extends State<ClusterAppBar> {
},
);
if (userConfirmed) {
+ Bus.instance.fire(PeopleChangedEvent());
+
// Close the old cluster page
+ if (!context.mounted) return;
Navigator.of(context).pop();
// Push the new cluster page
+ if (!context.mounted) return;
await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) =>
ClusterPage(biggestClusterFiles, clusterID: biggestClusterID),
),
);
- Bus.instance.fire(PeopleChangedEvent());
}
}
@@ -302,6 +306,7 @@ class _AppBarWidgetState extends State<ClusterAppBar> {
),
);
+ if (!context.mounted) return;
await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ClusterBreakupPage(
diff --git a/mobile/apps/photos/lib/ui/viewer/people/link_email_screen.dart b/mobile/apps/photos/lib/ui/viewer/people/link_email_screen.dart
index 8d9aa875da..741755921f 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/link_email_screen.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/link_email_screen.dart
@@ -221,6 +221,7 @@ class _LinkEmailScreen extends State<LinkEmailScreen> {
if (widget.isFromSaveOrEditPerson) {
await _emailHoldsEnteAccount(newEmail).then((value) {
if (value) {
+ if (!mounted) return;
Navigator.of(context).pop(newEmail);
}
});
@@ -236,8 +237,10 @@ class _LinkEmailScreen extends State<LinkEmailScreen> {
return;
}
+ if (!mounted) return;
Navigator.of(context).pop(newEmail);
} catch (e) {
+ if (!mounted) return;
await showGenericErrorDialog(context: context, error: e);
_logger.severe("Failed to link email to person", e);
}
@@ -271,12 +274,14 @@ class _LinkEmailScreen extends State<LinkEmailScreen> {
publicKey = await UserService.instance.getPublicKey(email);
} catch (e) {
_logger.severe("Failed to get public key", e);
+ if (!mounted) return false;
await showGenericErrorDialog(context: context, error: e);
return false;
}
// getPublicKey can return null when no user is associated with given
// email id
if (publicKey == null || publicKey == '') {
+ if (!mounted) return false;
await showDialogWidget(
context: context,
title: AppLocalizations.of(context).noEnteAccountExclamation,
@@ -316,6 +321,7 @@ class _LinkEmailScreen extends State<LinkEmailScreen> {
BuildContext context,
) async {
if (await checkIfEmailAlreadyAssignedToAPerson(email)) {
+ if (!context.mounted) return false;
await showAlreadyLinkedEmailDialog(context, email);
return false;
}
@@ -326,12 +332,14 @@ class _LinkEmailScreen extends State<LinkEmailScreen> {
publicKey = await UserService.instance.getPublicKey(email);
} catch (e) {
_logger.severe("Failed to get public key", e);
+ if (!context.mounted) return false;
await showGenericErrorDialog(context: context, error: e);
return false;
}
// getPublicKey can return null when no user is associated with given
// email id
if (publicKey == null || publicKey == '') {
+ if (!context.mounted) return false;
await showDialogWidget(
context: context,
title: AppLocalizations.of(context).noEnteAccountExclamation,
@@ -381,6 +389,7 @@ class _LinkEmailScreen extends State<LinkEmailScreen> {
return true;
} catch (e) {
_logger.severe("Failed to link email to person", e);
+ if (!context.mounted) return false;
await showGenericErrorDialog(context: context, error: e);
return false;
}
diff --git a/mobile/apps/photos/lib/ui/viewer/people/people_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/people/people_app_bar.dart
index 5449ef5126..2ea5c46121 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/people_app_bar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/people_app_bar.dart
@@ -499,6 +499,7 @@ class _AppBarWidgetState extends State<PeopleAppBar> {
firstButtonOnTap: () async {
try {
await PersonService.instance.deletePerson(person.remoteID);
+ if (!context.mounted) return;
Navigator.of(context).pop();
} catch (e, s) {
_logger.severe('Resetting person failed', e, s);
@@ -545,6 +546,7 @@ class _AppBarWidgetState extends State<PeopleAppBar> {
if (!mounted || result?.action != ButtonAction.error) {
return;
}
+ if (!context.mounted) return;
showShortToast(
context,
AppLocalizations.of(context).somethingWentWrongPleaseTryAgain,
@@ -602,6 +604,7 @@ class _AppBarWidgetState extends State<PeopleAppBar> {
!shouldCloseDetailPage) {
return;
}
+ if (!context.mounted) return;
await Navigator.of(context).maybePop();
}
@@ -609,9 +612,6 @@ class _AppBarWidgetState extends State<PeopleAppBar> {
final result = await showPersonAvatarPhotoSheet(context, person);
if (result != null) {
_logger.info('Person avatar updated');
- setState(() {
- person = result;
- });
Bus.instance.fire(
PeopleChangedEvent(
type: PeopleEventType.saveOrEditPerson,
@@ -619,6 +619,10 @@ class _AppBarWidgetState extends State<PeopleAppBar> {
person: result,
),
);
+ if (!mounted) return;
+ setState(() {
+ person = result;
+ });
}
}
diff --git a/mobile/apps/photos/lib/ui/viewer/people/person_selection_action_widgets.dart b/mobile/apps/photos/lib/ui/viewer/people/person_selection_action_widgets.dart
index e75bd5666d..9f0dd0d53f 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/person_selection_action_widgets.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/person_selection_action_widgets.dart
@@ -344,14 +344,16 @@ class _LinkContactToPersonSelectionPageState
);
if (updatedPerson != null) {
+ if (!context.mounted) return;
Navigator.of(context).pop(updatedPerson);
}
} catch (e) {
+ _logger.severe("Failed to link person to contact", e);
+ if (!context.mounted) return;
await showGenericErrorDialog(
context: context,
error: e,
);
- _logger.severe("Failed to link person to contact", e);
}
},
itemSize: itemSize,
@@ -523,12 +525,14 @@ class _LinkContactToPersonSelectionPageState
required PersonEntity personEntity,
}) async {
if (await checkIfEmailAlreadyAssignedToAPerson(emailToLink)) {
+ if (!context.mounted) return null;
await showAlreadyLinkedEmailDialog(context, emailToLink);
return null;
}
final personName = personEntity.data.name;
PersonEntity? updatedPerson;
+ if (!context.mounted) return null;
final result = await showDialogWidget(
context: context,
title: context.l10n.linkPersonToEmail(email: emailToLink),
@@ -571,6 +575,7 @@ class _LinkContactToPersonSelectionPageState
Logger(
"linkPersonToContact",
).severe("Failed to link person to contact", result!.exception);
+ if (!context.mounted) return null;
await showGenericErrorDialog(context: context, error: result.exception);
return null;
} else {
@@ -687,6 +692,7 @@ class _ReassignMeSelectionPageState extends State<ReassignMeSelectionPage> {
currentPersonID: widget.currentMeId,
newPersonID: results[index].remoteID,
);
+ if (!context.mounted) return;
showToast(
context,
context.l10n.reassignedToName(
@@ -695,9 +701,11 @@ class _ReassignMeSelectionPageState extends State<ReassignMeSelectionPage> {
);
await Future.delayed(const Duration(milliseconds: 1250));
unawaited(dialog.hide());
+ if (!context.mounted) return;
Navigator.of(context).pop();
} catch (e) {
unawaited(dialog.hide());
+ if (!context.mounted) return;
unawaited(
showGenericErrorDialog(context: context, error: e),
);
diff --git a/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dart b/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dart
index e41cf21f43..11d1886aa7 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dart
@@ -324,6 +324,7 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
context,
);
if (updatedPersonEntity != null) {
+ if (!context.mounted) return;
Navigator.pop(context, updatedPersonEntity);
}
} else {
@@ -342,6 +343,7 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
return null;
});
if (newPersonEntity != null) {
+ if (!context.mounted) return;
Navigator.pop(context, newPersonEntity);
}
}
@@ -596,6 +598,7 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
_logger.severe(
"Failed to addNewPerson, email is already assigned to a person",
);
+ if (!context.mounted) return null;
await showAlreadyLinkedEmailDialog(context, email);
return null;
}
@@ -618,7 +621,7 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
);
final bool extraPhotosFound = await ClusterFeedbackService.instance
.checkAndDoAutomaticMerges(personEntity, personClusterID: clusterID);
- if (extraPhotosFound) {
+ if (extraPhotosFound && context.mounted) {
showShortToast(context, AppLocalizations.of(context).extraPhotosFound);
}
Bus.instance.fire(
@@ -632,6 +635,7 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
} catch (e) {
_logger.severe("Error adding new person", e);
userAlreadyAssigned = false;
+ if (!context.mounted) return null;
await showGenericErrorDialog(context: context, error: e);
return null;
}
@@ -651,6 +655,7 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
_email!.isNotEmpty &&
_email != person!.data.email &&
await checkIfEmailAlreadyAssignedToAPerson(_email!)) {
+ if (!context.mounted) return null;
await showAlreadyLinkedEmailDialog(context, _email!);
return null;
}
@@ -675,6 +680,7 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
return personEntity;
} catch (e) {
_logger.severe("Error adding updating person", e);
+ if (!context.mounted) return null;
await showGenericErrorDialog(context: context, error: e);
return null;
}
diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/no_result_widget.dart b/mobile/apps/photos/lib/ui/viewer/search/result/no_result_widget.dart
index ba1887ec9b..544b18a9b8 100644
--- a/mobile/apps/photos/lib/ui/viewer/search/result/no_result_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search/result/no_result_widget.dart
@@ -31,6 +31,7 @@ class _NoResultWidgetState extends State<NoResultWidget> {
InheritedAllSectionsExamples.of(context).allSectionsExamplesFuture.then((
value,
) {
+ if (!mounted) return;
final sectionResultsByType = value.sectionResults;
if (sectionResultsByType.isEmpty) return;
for (int i = 0; i < searchTypes.length; i++) {
diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dart
index 76de65e0ba..a0b2d8694a 100644
--- a/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dart
@@ -47,12 +47,13 @@ class _LocationsSectionState extends State<LocationsSection> {
for (Stream<Event> stream in streamsToListenTo) {
streamSubscriptions.add(
stream.listen((event) async {
- _locationsSearchResults =
- (await SectionType.location.getData(
- context,
- limit: widget.resultLimit + 1,
- ))
- as List<GenericSearchResult>;
+ if (!mounted) return;
+ final results = await SectionType.location.getData(
+ context,
+ limit: widget.resultLimit + 1,
+ );
+ if (!mounted) return;
+ _locationsSearchResults = results as List<GenericSearchResult>;
setState(() {});
}),
);
diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/magic_section.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/magic_section.dart
index 72c8affd85..94881f768c 100644
--- a/mobile/apps/photos/lib/ui/viewer/search_tab/magic_section.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/magic_section.dart
@@ -40,12 +40,13 @@ class _MagicSectionState extends State<MagicSection> {
for (Stream<Event> stream in streamsToListenTo) {
streamSubscriptions.add(
stream.listen((event) async {
- _magicSearchResults =
- (await SectionType.magic.getData(
- context,
- limit: widget.resultLimit + 1,
- ))
- as List<GenericSearchResult>;
+ if (!mounted) return;
+ final results = await SectionType.magic.getData(
+ context,
+ limit: widget.resultLimit + 1,
+ );
+ if (!mounted) return;
+ _magicSearchResults = results as List<GenericSearchResult>;
setState(() {});
}),
);
diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/people_section.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/people_section.dart
index 0b9661a896..4bcb97be7a 100644
--- a/mobile/apps/photos/lib/ui/viewer/search_tab/people_section.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/people_section.dart
@@ -56,12 +56,13 @@ class _PeopleSectionState extends State<PeopleSection> {
for (Stream<Event> stream in streamsToListenTo) {
streamSubscriptions.add(
stream.listen((event) async {
- _examples =
- await widget.sectionType.getData(
- context,
- limit: widget.resultLimit + 1,
- )
- as List<GenericSearchResult>;
+ if (!mounted) return;
+ final results = await widget.sectionType.getData(
+ context,
+ limit: widget.resultLimit + 1,
+ );
+ if (!mounted) return;
+ _examples = results as List<GenericSearchResult>;
setState(() {});
}),
);
@@ -292,6 +293,7 @@ class PersonSearchExample extends StatelessWidget {
);
if (result != null &&
result is (PersonEntity, EnteFile)) {
+ if (!context.mounted) return;
// ignore: unawaited_futures
routeToPage(
context,
@@ -302,6 +304,7 @@ class PersonSearchExample extends StatelessWidget {
);
} else if (result != null &&
result is PersonEntity) {
+ if (!context.mounted) return;
// ignore: unawaited_futures
routeToPage(
context,
diff --git a/mobile/apps/photos/lib/ui/wrapped/wrapped_viewer_page.dart b/mobile/apps/photos/lib/ui/wrapped/wrapped_viewer_page.dart
index 97ef2faccc..4bf619b46a 100644
--- a/mobile/apps/photos/lib/ui/wrapped/wrapped_viewer_page.dart
+++ b/mobile/apps/photos/lib/ui/wrapped/wrapped_viewer_page.dart
@@ -525,6 +525,7 @@ class _WrappedViewerPageState extends State<WrappedViewerPage>
if (!_didRegisterWillPop) {
await _fadeOutAndStopMusic();
}
+ if (!mounted) return;
final bool didPop = await Navigator.of(context).maybePop();
if (!didPop && mounted) {
_isClosing = false;
@@ -941,9 +942,11 @@ class _WrappedViewerPageState extends State<WrappedViewerPage>
hideInteractiveControls: hideShareControls,
);
if (bytes == null) {
+ if (!mounted) return;
showShortToast(context, "Unable to prepare share");
return;
}
+ if (!mounted) return;
await SharePlus.instance.share(
ShareParams(
files: <XFile>[
diff --git a/mobile/apps/photos/lib/utils/delete_file_util.dart b/mobile/apps/photos/lib/utils/delete_file_util.dart
index 2a825e2581..614f11d3dc 100644
--- a/mobile/apps/photos/lib/utils/delete_file_util.dart
+++ b/mobile/apps/photos/lib/utils/delete_file_util.dart
@@ -129,10 +129,12 @@ Future<void> deleteFilesFromEverywhere(
source: "deleteFilesEverywhere",
),
);
- if (hasLocalOnlyFiles && Platform.isAndroid) {
- showShortToast(context, AppLocalizations.of(context).filesDeleted);
- } else {
- showShortToast(context, AppLocalizations.of(context).movedToTrash);
+ if (context.mounted) {
+ if (hasLocalOnlyFiles && Platform.isAndroid) {
+ showShortToast(context, AppLocalizations.of(context).filesDeleted);
+ } else {
+ showShortToast(context, AppLocalizations.of(context).movedToTrash);
+ }
}
}
if (uploadedFilesToBeTrashed.isNotEmpty) {
@@ -303,6 +305,7 @@ Future<bool> deleteFromTrash(BuildContext context, List<EnteFile> files) async {
actionResult.action == ButtonAction.fourth) {
return didDeletionStart ? true : false;
} else if (actionResult.action == ButtonAction.error) {
+ if (!context.mounted) return false;
await showGenericErrorDialog(
context: context,
error: actionResult.exception,
@@ -333,6 +336,7 @@ Future<bool> emptyTrash(BuildContext context) async {
actionResult!.action == ButtonAction.cancel) {
return false;
} else if (actionResult.action == ButtonAction.error) {
+ if (!context.mounted) return false;
await showGenericErrorDialog(
context: context,
error: actionResult.exception,
@@ -377,6 +381,7 @@ Future<bool> deleteLocalFiles(
_logger.info(
"Too many assets (${localAssetIDs.length}) to delete in one shot, deleting in batches",
);
+ if (!context.mounted) return false;
await _recursivelyReduceBatchSizeAndRetryDeletion(
batchSize: largeCountThreshold,
context: context,
@@ -385,12 +390,14 @@ Future<bool> deleteLocalFiles(
);
} else {
_logger.info("Deleting in batches");
+ if (!context.mounted) return false;
deletedIDs.addAll(
await deleteLocalFilesInBatches(context, localAssetIDs),
);
}
} else {
_logger.info("Deleting in one shot");
+ if (!context.mounted) return false;
deletedIDs.addAll(
await _deleteLocalFilesInOneShot(context, localAssetIDs),
);
@@ -464,11 +471,13 @@ Future<bool> deleteLocalFilesAfterRemovingAlreadyDeletedIDs(
);
if (shouldDeleteInBatches) {
_logger.info("Deleting in batches");
+ if (!context.mounted) return false;
deletedIDs.addAll(
await deleteLocalFilesInBatches(context, localAssetIDs),
);
} else {
_logger.info("Deleting in one shot");
+ if (!context.mounted) return false;
deletedIDs.addAll(
await _deleteLocalFilesInOneShot(context, localAssetIDs),
);
@@ -550,11 +559,13 @@ Future<bool> retryFreeUpSpaceAfterRemovingAssetsNonExistingInDisk(
);
if (shouldDeleteInBatches) {
_logger.info("Deleting in batches");
+ if (!context.mounted) return false;
deletedIDs.addAll(
await deleteLocalFilesInBatches(context, localAssetIDs),
);
} else {
_logger.info("Deleting in one shot");
+ if (!context.mounted) return false;
deletedIDs.addAll(
await _deleteLocalFilesInOneShot(context, localAssetIDs),
);
@@ -696,6 +707,7 @@ Future<void> _recursivelyReduceBatchSizeAndRetryDeletion({
"Failed to delete local files in batches of $batchSize. Reducing batch size and retrying.",
e,
);
+ if (!context.mounted) return;
await _recursivelyReduceBatchSizeAndRetryDeletion(
batchSize: (batchSize / 2).floor(),
context: context,
@@ -762,6 +774,7 @@ Future<void> showMediaManagementHintSheet(BuildContext context) async {
if (!localSettings.hasMediaManagementHintDeleteAttemptsReached()) {
return;
}
+ if (!context.mounted) return;
final shouldDismissHint = await showBottomSheetComponent<bool>(
context: context,
useRootNavigator: Platform.isIOS,
@@ -847,6 +860,7 @@ Future<void> showDeleteSheet(
}
var didDelete = false;
if (Platform.isAndroid && await MediaStoreService.canManageMedia()) {
+ if (!context.mounted) return;
didDelete =
await showBottomSheetComponent<bool>(
context: context,
@@ -873,6 +887,7 @@ Future<void> showDeleteSheet(
) ==
true;
} else {
+ if (!context.mounted) return;
await deleteOnDeviceOnlyAction(context, localGalleryDeletableFiles);
didDelete = true;
}
@@ -880,6 +895,7 @@ Future<void> showDeleteSheet(
return;
}
selectedFiles.unSelectAll(localGalleryDeletableFiles.toSet());
+ if (!context.mounted) return;
await showMediaManagementHintSheet(context);
return;
}
@@ -895,6 +911,7 @@ Future<void> showDeleteSheet(
Future<void> deleteFromEnte() async {
await deleteFromRemoteOnlyAction(context, deletableFiles);
+ if (!context.mounted) return;
showShortToast(context, l10n.movedToTrash);
}
@@ -922,6 +939,7 @@ Future<void> showDeleteSheet(
if (actionResult == true) {
selectedFiles.clearAll();
if (didDeleteLocalFiles) {
+ if (!context.mounted) return;
await showMediaManagementHintSheet(context);
}
}
@@ -1130,6 +1148,7 @@ class DeleteConfirmationSheetState extends State<DeleteConfirmationSheet> {
.DeleteFromLocalOnly,
);
}
+ if (!context.mounted) return;
await _onDelete(context, widget.onDeleteFromLocal);
},
),
@@ -1142,6 +1161,7 @@ class DeleteConfirmationSheetState extends State<DeleteConfirmationSheet> {
.DeleteFromRemoteOnly,
);
}
+ if (!context.mounted) return;
await _onDelete(context, widget.onDeleteFromRemote);
},
),
@@ -1154,6 +1174,7 @@ class DeleteConfirmationSheetState extends State<DeleteConfirmationSheet> {
.DeleteFromBoth,
);
}
+ if (!context.mounted) return;
await _onDelete(context, widget.onDeleteFromBoth);
},
),
diff --git a/mobile/apps/photos/lib/utils/email_util.dart b/mobile/apps/photos/lib/utils/email_util.dart
index b79d87c971..56abcfdcb4 100644
--- a/mobile/apps/photos/lib/utils/email_util.dart
+++ b/mobile/apps/photos/lib/utils/email_util.dart
@@ -92,6 +92,7 @@ Future<void> sendLogs(
shouldSurfaceExecutionStates: false,
onTap: () async {
final zipFilePath = await getZippedLogsFile(context);
+ if (!context.mounted) return;
await exportLogs(context, zipFilePath);
},
),
@@ -112,6 +113,7 @@ Future<void> _sendLogs(
String? body,
) async {
final String zipFilePath = await getZippedLogsFile(context);
+ if (!context.mounted) return;
final didOpenComposer = await sendLogsWithSubjectAndBody(
context,
toEmail: toEmail,
@@ -120,7 +122,9 @@ Future<void> _sendLogs(
zipFilePath: zipFilePath,
);
if (!didOpenComposer) {
+ if (!context.mounted) return;
Navigator.of(context).pop();
+ if (!context.mounted) return;
await shareLogs(context, toEmail, zipFilePath);
}
}
@@ -133,6 +137,7 @@ Future<bool> sendLogsWithSubjectAndBody(
String? zipFilePath,
}) async {
final effectiveZipFilePath = zipFilePath ?? await getZippedLogsFile(context);
+ if (!context.mounted) return false;
return sendComposedEmail(
context,
to: toEmail,
@@ -221,6 +226,7 @@ Future<void> shareLogs(
],
);
if (result?.action != null && result!.action == ButtonAction.second) {
+ if (!context.mounted) return;
await exportLogs(context, zipFilePath);
}
}
@@ -256,6 +262,7 @@ Future<void> sendEmail(
}) async {
try {
final String clientDebugInfo = await _clientInfo();
+ if (!context.mounted) return;
final didOpenComposer = await sendComposedEmail(
context,
to: to,
@@ -263,10 +270,12 @@ Future<void> sendEmail(
body: (body ?? '') + clientDebugInfo,
);
if (!didOpenComposer) {
+ if (!context.mounted) return;
await _showNoMailAppsSheet(context, to);
}
} catch (e) {
_logger.severe("Failed to send emailContent to $to", e);
+ if (!context.mounted) return;
await _showNoMailAppsSheet(context, to);
}
}
@@ -283,10 +292,12 @@ Future<void> openEmailComposer(
body: '',
);
if (!didOpenComposer) {
+ if (!context.mounted) return;
await _showNoMailAppsSheet(context, to);
}
} catch (e, s) {
_logger.severe("Failed to open email composer to $to", e, s);
+ if (!context.mounted) return;
await _showNoMailAppsSheet(context, to);
}
}
@@ -333,6 +344,7 @@ Future<bool> sendComposedEmail(
return false;
}
if (!result.didOpen && result.canOpen) {
+ if (!context.mounted) return false;
await showCupertinoModalPopup(
context: context,
builder: (_) => CupertinoActionSheet(
diff --git a/mobile/apps/photos/lib/utils/magic_util.dart b/mobile/apps/photos/lib/utils/magic_util.dart
index f4b22abcbd..cb3be932e5 100644
--- a/mobile/apps/photos/lib/utils/magic_util.dart
+++ b/mobile/apps/photos/lib/utils/magic_util.dart
@@ -38,14 +38,15 @@ Future<void> changeVisibility(
await dialog.show();
try {
await FileMagicService.instance.changeVisibility(files, newVisibility);
- showShortToast(
- context,
- newVisibility == archiveVisibility
- ? AppLocalizations.of(context).successfullyArchived
- : AppLocalizations.of(context).successfullyUnarchived,
- );
-
await dialog.hide();
+ if (context.mounted) {
+ showShortToast(
+ context,
+ newVisibility == archiveVisibility
+ ? AppLocalizations.of(context).successfullyArchived
+ : AppLocalizations.of(context).successfullyUnarchived,
+ );
+ }
} catch (e, s) {
_logger.severe("failed to update file visibility", e, s);
await dialog.hide();
@@ -92,14 +93,13 @@ Future<void> changeCollectionVisibility(
"CollectionVisibilityChange: $visibilityAction",
),
);
- if (showProgressDialog) {
+ await dialog?.hide();
+ if (showProgressDialog && context.mounted) {
showShortToast(
context,
_visActionSuccessfulText(context, visibilityAction),
);
}
-
- await dialog?.hide();
} catch (e, s) {
_logger.severe("failed to update collection visibility", e, s);
await dialog?.hide();
@@ -123,7 +123,9 @@ Future<void> changeSortOrder(
);
} catch (e, s) {
_logger.severe("failed to update collection visibility", e, s);
- showShortToast(context, AppLocalizations.of(context).somethingWentWrong);
+ if (context.mounted) {
+ showShortToast(context, AppLocalizations.of(context).somethingWentWrong);
+ }
rethrow;
}
}
@@ -141,7 +143,9 @@ Future<void> updateOrder(
);
} catch (e, s) {
_logger.severe("failed to update order", e, s);
- showShortToast(context, AppLocalizations.of(context).somethingWentWrong);
+ if (context.mounted) {
+ showShortToast(context, AppLocalizations.of(context).somethingWentWrong);
+ }
rethrow;
}
}
@@ -162,7 +166,9 @@ Future<void> updateShareeOrder(
);
} catch (e, s) {
_logger.severe("failed to update sharee order", e, s);
- showShortToast(context, AppLocalizations.of(context).somethingWentWrong);
+ if (context.mounted) {
+ showShortToast(context, AppLocalizations.of(context).somethingWentWrong);
+ }
rethrow;
}
}
@@ -190,7 +196,9 @@ Future<void> changeCoverPhoto(
);
} catch (e, s) {
_logger.severe("failed to update cover", e, s);
- showShortToast(context, AppLocalizations.of(context).somethingWentWrong);
+ if (context.mounted) {
+ showShortToast(context, AppLocalizations.of(context).somethingWentWrong);
+ }
rethrow;
}
}
@@ -236,8 +244,10 @@ Future<bool> editTime(
ForceReloadHomeGalleryEvent("FileMetadataChange-$editTimeKey"),
);
}
- showShortToast(context, AppLocalizations.of(context).done);
await dialog.hide();
+ if (context.mounted) {
+ showShortToast(context, AppLocalizations.of(context).done);
+ }
} catch (e, s) {
_logger.severe("failed to update times $fileIdToTimeUpdate", e, s);
await dialog.hide();
@@ -245,6 +255,7 @@ Future<bool> editTime(
}
return true;
} catch (e) {
+ if (!context.mounted) return false;
showShortToast(context, AppLocalizations.of(context).somethingWentWrong);
return false;
}
@@ -281,6 +292,7 @@ Future<void> editFilename(BuildContext context, EnteFile file) async {
);
if (result is Exception) {
_logger.severe("Failed to rename file");
+ if (!context.mounted) return;
await showGenericErrorDialog(context: context, error: result);
}
}
@@ -328,10 +340,10 @@ Future<void> _updatePublicMetadata(
final Map<String, dynamic> update = {key: value};
await FileMagicService.instance.updatePublicMagicMetadata(files, update);
if (context != null) {
- if (showDoneToast) {
+ await dialog?.hide();
+ if (showDoneToast && context.mounted) {
showShortToast(context, AppLocalizations.of(context).done);
}
- await dialog?.hide();
}
if (_shouldReloadGallery(key)) {
diff --git a/mobile/apps/photos/lib/utils/person_contact_linking_util.dart b/mobile/apps/photos/lib/utils/person_contact_linking_util.dart
index 4e014e30e7..815b1c2d38 100644
--- a/mobile/apps/photos/lib/utils/person_contact_linking_util.dart
+++ b/mobile/apps/photos/lib/utils/person_contact_linking_util.dart
@@ -29,6 +29,7 @@ Future<void> showAlreadyLinkedEmailDialog(
return;
}
+ if (!context.mounted) return;
await showChoiceActionSheet(
context,
title: context.l10n.error,
diff --git a/mobile/apps/photos/lib/utils/share_util.dart b/mobile/apps/photos/lib/utils/share_util.dart
index d688d26ba8..804ce52dac 100644
--- a/mobile/apps/photos/lib/utils/share_util.dart
+++ b/mobile/apps/photos/lib/utils/share_util.dart
@@ -77,6 +77,7 @@ Future<void> share(
throw ArgumentError("No files resolved for system share");
}
final xFiles = resolvedPaths.map((path) => XFile(path)).toList();
+ if (!context.mounted) return;
await SharePlus.instance.share(
ShareParams(
files: xFiles,
@@ -91,6 +92,7 @@ Future<void> share(
s,
);
await dialog.hide();
+ if (!context.mounted) return;
await showGenericErrorDialog(context: context, error: e);
}
}