π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Enforce async BuildContext lint in Auth
Neeraj Gupta5a2b6c52a933
diff --git a/mobile/apps/auth/analysis_options.yaml b/mobile/apps/auth/analysis_options.yamlindex d937453c88..333c537330 100644--- a/mobile/apps/auth/analysis_options.yaml+++ b/mobile/apps/auth/analysis_options.yaml@@ -49,8 +49,8 @@ analyzer:unawaited_futures: warning # convert to warning after fixing existing issuesavoid_renaming_method_parameters: ignore # incorrect warnings for `equals` overrides- use_build_context_synchronously: ignore # experimental lint, requires many changes+ use_build_context_synchronously: errorexclude:- thirdparty/**- - flutter/**\ No newline at end of file+ - flutter/**diff --git a/mobile/apps/auth/lib/app/view/app.dart b/mobile/apps/auth/lib/app/view/app.dartindex 864cac204f..8ed87a68d7 100644--- a/mobile/apps/auth/lib/app/view/app.dart+++ b/mobile/apps/auth/lib/app/view/app.dart@@ -89,6 +89,7 @@ class _AppState extends State<App> with WidgetsBindingObserver {UpdateService.instance.showUpdateNotification().then((shouldUpdate) {if (shouldUpdate) {Future.delayed(Duration.zero, () {+ if (!mounted) return;showDialog(context: context,builder: (BuildContext context) {diff --git a/mobile/apps/auth/lib/onboarding/view/common/edit_tag.dart b/mobile/apps/auth/lib/onboarding/view/common/edit_tag.dartindex 45b6c240c1..05aa83596c 100644--- a/mobile/apps/auth/lib/onboarding/view/common/edit_tag.dart+++ b/mobile/apps/auth/lib/onboarding/view/common/edit_tag.dart@@ -72,6 +72,7 @@ class _EditTagDialogState extends State<EditTagDialog> {await dialog.hide();+ if (!context.mounted) return;Navigator.pop(context);},),diff --git a/mobile/apps/auth/lib/onboarding/view/onboarding_page.dart b/mobile/apps/auth/lib/onboarding/view/onboarding_page.dartindex 5af60c5129..2516930784 100644--- a/mobile/apps/auth/lib/onboarding/view/onboarding_page.dart+++ b/mobile/apps/auth/lib/onboarding/view/onboarding_page.dart@@ -63,6 +63,7 @@ class _OnboardingPageState extends State<OnboardingPage> {_triggerLogoutEvent = Bus.instance.on<TriggerLogoutEvent>().listen((event,) async {+ if (!mounted) return;await autoLogoutAlert(context);});_startAutoScroll();@@ -98,6 +99,7 @@ class _OnboardingPageState extends State<OnboardingPage> {GestureDetector(onTap: () async {final locale = (await getLocale())!;+ if (!context.mounted) return;unawaited(routeToPage(context,@@ -105,6 +107,7 @@ class _OnboardingPageState extends State<OnboardingPage> {locale,) async {await setLocale(locale);+ if (!context.mounted) return;App.setLocale(context, locale);}, locale),).then((value) {@@ -242,6 +245,7 @@ class _OnboardingPageState extends State<OnboardingPage> {Platform.isWindows ||await LocalAuthentication().canCheckBiometrics;if (!canCheckBio) {+ if (!mounted) return;showToast(context,"Sorry, biometric authentication is not supported on this device.",@@ -251,6 +255,7 @@ class _OnboardingPageState extends State<OnboardingPage> {final bool hasOptedBefore = Configuration.instance.hasOptedForOfflineMode();ButtonResult? result;if (!hasOptedBefore) {+ if (!mounted) return;result = await showChoiceActionSheet(context,title: context.l10n.warning,@@ -260,7 +265,9 @@ class _OnboardingPageState extends State<OnboardingPage> {);}if (hasOptedBefore || result?.action == ButtonAction.first) {+ if (!context.mounted) return;await Configuration.instance.optForOfflineMode();+ if (!mounted) return;unawaited(Navigator.of(context).pushReplacement(MaterialPageRoute(diff --git a/mobile/apps/auth/lib/onboarding/view/setup_enter_secret_key_page.dart b/mobile/apps/auth/lib/onboarding/view/setup_enter_secret_key_page.dartindex ff468a8db0..9ecc26a801 100644--- a/mobile/apps/auth/lib/onboarding/view/setup_enter_secret_key_page.dart+++ b/mobile/apps/auth/lib/onboarding/view/setup_enter_secret_key_page.dart@@ -422,6 +422,7 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {Future<void> _saveCode() async {try {+ if (!mounted) return;final account = _accountController.text.trim();final issuer = _issuerController.text.trim();final secret = _secretController.text.trim().replaceAll(' ', '');@@ -487,6 +488,7 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {// Verify the validity of the codegetOTP(newCode);+ if (!mounted) return;Navigator.of(context).pop(newCode);} catch (e, s) {_logger.severe("Error saving code", e, s);diff --git a/mobile/apps/auth/lib/ui/account/logout_dialog.dart b/mobile/apps/auth/lib/ui/account/logout_dialog.dartindex 4f9af8ca72..4f55a0a699 100644--- a/mobile/apps/auth/lib/ui/account/logout_dialog.dart+++ b/mobile/apps/auth/lib/ui/account/logout_dialog.dart@@ -29,6 +29,7 @@ Future<void> autoLogoutAlert(BuildContext context) async {int pendingSyncCount = await AuthenticatorDB.instance.getNeedSyncCount();if (pendingSyncCount > 0) {+ if (!context.mounted) return;// ignore: unawaited_futuresshowChoiceActionSheet(context,@@ -41,6 +42,7 @@ Future<void> autoLogoutAlert(BuildContext context) async {},);} else {+ if (!context.mounted) return;await _logout(context, l10n);}},diff --git a/mobile/apps/auth/lib/ui/code_widget.dart b/mobile/apps/auth/lib/ui/code_widget.dartindex 7f69e5e481..923969e489 100644--- a/mobile/apps/auth/lib/ui/code_widget.dart+++ b/mobile/apps/auth/lib/ui/code_widget.dart@@ -894,6 +894,7 @@ class _CodeWidgetState extends State<CodeWidget> {.shouldMinimizeOnCopy();await FlutterClipboard.copy(content);+ if (!mounted) return;showToast(context, confirmationMessage);if (Platform.isAndroid && shouldMinimizeOnCopy) {// ignore: unawaited_futures@@ -917,6 +918,7 @@ class _CodeWidgetState extends State<CodeWidget> {if (!isAuthSuccessful) {return;}+ if (!mounted) return;final Code? code = await Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) {@@ -944,6 +946,7 @@ class _CodeWidgetState extends State<CodeWidget> {.replaceAll('algorithm=sha256', 'algorithm=SHA256').replaceAll('algorithm=sha512', 'algorithm=SHA512');+ if (!mounted) return;await showDialog(context: context,builder: (BuildContext dialogContext) {@@ -972,6 +975,7 @@ class _CodeWidgetState extends State<CodeWidget> {if (!isAuthSuccessful) {return;}+ if (!mounted) return;showShareDialog(context, widget.code);}@@ -984,17 +988,17 @@ class _CodeWidgetState extends State<CodeWidget> {final Code code = widget.code.copyWith(display: display.copyWith(pinned: !currentlyPinned),);+ if (!mounted) return;unawaited(- CodeStore.instance- .addCode(code)- .then(- (value) => showToast(- context,- !currentlyPinned- ? context.l10n.pinnedCodeMessage(widget.code.issuer)- : context.l10n.unpinnedCodeMessage(widget.code.issuer),- ),- ),+ CodeStore.instance.addCode(code).then((value) {+ if (!mounted) return;+ showToast(+ context,+ !currentlyPinned+ ? context.l10n.pinnedCodeMessage(widget.code.issuer)+ : context.l10n.unpinnedCodeMessage(widget.code.issuer),+ );+ }),);}@@ -1014,8 +1018,10 @@ class _CodeWidgetState extends State<CodeWidget> {if (!isAuthSuccessful) {return;}+ if (!mounted) return;FocusScope.of(context).requestFocus();final l10n = context.l10n;+ if (!mounted) return;await showChoiceActionSheet(context,title: l10n.deleteCodeTitle,@@ -1028,6 +1034,7 @@ class _CodeWidgetState extends State<CodeWidget> {LocalBackupService.instance.triggerDailyBackupIfNeeded().ignore();} catch (e, s) {logger.severe('Failed to delete code', e, s);+ if (!mounted) return;showGenericErrorDialog(context: context, error: e).ignore();}},@@ -1050,11 +1057,13 @@ class _CodeWidgetState extends State<CodeWidget> {if (!isAuthSuccessful) {return;}+ if (!mounted) return;FocusScope.of(context).requestFocus();final l10n = context.l10n;final String issuerAccount = widget.code.account.isNotEmpty? '${widget.code.issuer} (${widget.code.account})': widget.code.issuer;+ if (!mounted) return;await showChoiceActionSheet(context,title: l10n.trashCode,@@ -1070,6 +1079,7 @@ class _CodeWidgetState extends State<CodeWidget> {await CodeStore.instance.addCode(code);} catch (e) {logger.severe('Failed to trash code: ${e.toString()}');+ if (!mounted) return;showGenericErrorDialog(context: context, error: e).ignore();}},diff --git a/mobile/apps/auth/lib/ui/components/auth_qr_dialog.dart b/mobile/apps/auth/lib/ui/components/auth_qr_dialog.dartindex 9370b4778c..0f37fbe8da 100644--- a/mobile/apps/auth/lib/ui/components/auth_qr_dialog.dart+++ b/mobile/apps/auth/lib/ui/components/auth_qr_dialog.dart@@ -41,6 +41,7 @@ class _AuthQrDialogState extends State<AuthQrDialog> {Future<void> _shareQrCode() async {try {+ if (!mounted) return;final boundary =_qrKey.currentContext?.findRenderObject() as RenderRepaintBoundary?;if (boundary == null) return;@@ -56,6 +57,7 @@ class _AuthQrDialogState extends State<AuthQrDialog> {final file = File('${directory.path}/${widget.shareFileName}');await file.writeAsBytes(pngBytes);+ if (!mounted) return;final box = context.findRenderObject() as RenderBox?;final shareOrigin = box != null? box.localToGlobal(Offset.zero) & box.sizediff --git a/mobile/apps/auth/lib/ui/components/buttons/button_widget.dart b/mobile/apps/auth/lib/ui/components/buttons/button_widget.dartindex ca233b825d..0c1c91cedd 100644--- a/mobile/apps/auth/lib/ui/components/buttons/button_widget.dart+++ b/mobile/apps/auth/lib/ui/components/buttons/button_widget.dart@@ -451,6 +451,7 @@ class _ButtonChildWidgetState extends State<ButtonChildWidget> {}if (executionState == ExecutionState.inProgress ||executionState == ExecutionState.error) {+ if (!mounted) return;if (executionState == ExecutionState.inProgress) {if (mounted) {setState(() {@@ -462,6 +463,7 @@ class _ButtonChildWidgetState extends State<ButtonChildWidget> {: 0,),() {+ if (!mounted) return;widget.isInAlert? _popWithButtonAction(context,@@ -482,14 +484,14 @@ class _ButtonChildWidgetState extends State<ButtonChildWidget> {setState(() {executionState = ExecutionState.idle;widget.isInAlert- ? Future.delayed(- const Duration(seconds: 0),- () => _popWithButtonAction(+ ? Future.delayed(const Duration(seconds: 0), () {+ if (!mounted) return;+ _popWithButtonAction(context,buttonAction: ButtonAction.error,exception: _exception,- ),- )+ );+ }): null;});}@@ -497,8 +499,10 @@ class _ButtonChildWidgetState extends State<ButtonChildWidget> {if (widget.isInAlert) {Future.delayed(Duration(seconds: widget.shouldShowSuccessConfirmation ? 1 : 0),- () =>- _popWithButtonAction(context, buttonAction: widget.buttonAction),+ () {+ if (!mounted) return;+ _popWithButtonAction(context, buttonAction: widget.buttonAction);+ },);}}diff --git a/mobile/apps/auth/lib/ui/components/note_dialog.dart b/mobile/apps/auth/lib/ui/components/note_dialog.dartindex 92f1864280..14ce5ac2dc 100644--- a/mobile/apps/auth/lib/ui/components/note_dialog.dart+++ b/mobile/apps/auth/lib/ui/components/note_dialog.dart@@ -143,6 +143,7 @@ Future<void> showNotesDialog(BuildContext context, String note) async {customBorder: const CircleBorder(),onTap: () async {await FlutterClipboard.copy(trimmedNote);+ if (!dialogContext.mounted) return;Navigator.of(dialogContext).pop();showToast(dialogContext,diff --git a/mobile/apps/auth/lib/ui/components/recovery_key_sheet.dart b/mobile/apps/auth/lib/ui/components/recovery_key_sheet.dartindex c8e1ea3644..3ddc5ae8f8 100644--- a/mobile/apps/auth/lib/ui/components/recovery_key_sheet.dart+++ b/mobile/apps/auth/lib/ui/components/recovery_key_sheet.dart@@ -136,11 +136,13 @@ class _RecoveryKeySheetState extends State<RecoveryKeySheet> {Future<void> _shareRecoveryKey(String recoveryKey) async {try {+ if (!mounted) return;if (_recoveryKeyFile.existsSync()) {await _recoveryKeyFile.delete();}_recoveryKeyFile.writeAsStringSync(recoveryKey);+ if (!mounted) return;await shareFiles([XFile(_recoveryKeyFile.path, mimeType: 'text/plain'),], context: context);diff --git a/mobile/apps/auth/lib/ui/components/text_input_widget.dart b/mobile/apps/auth/lib/ui/components/text_input_widget.dartindex 8986f967ee..ce2a8a26f5 100644--- a/mobile/apps/auth/lib/ui/components/text_input_widget.dart+++ b/mobile/apps/auth/lib/ui/components/text_input_widget.dart@@ -264,6 +264,7 @@ class _TextInputWidgetState extends State<TextInputWidget> {await Future.delayed(const Duration(milliseconds: 5));if (executionState == ExecutionState.inProgress ||executionState == ExecutionState.error) {+ if (!mounted) return;if (executionState == ExecutionState.inProgress) {if (mounted) {if (widget.showOnlyLoadingState) {@@ -281,6 +282,7 @@ class _TextInputWidgetState extends State<TextInputWidget> {: 0,),() {+ if (!mounted) return;widget.popNavAfterSubmission? _popNavigatorStack(context): null;@@ -299,10 +301,10 @@ class _TextInputWidgetState extends State<TextInputWidget> {setState(() {executionState = ExecutionState.idle;widget.popNavAfterSubmission- ? Future.delayed(- const Duration(seconds: 0),- () => _popNavigatorStack(context, e: _exception),- )+ ? Future.delayed(const Duration(seconds: 0), () {+ if (!mounted) return;+ _popNavigatorStack(context, e: _exception);+ }): null;});}@@ -310,7 +312,10 @@ class _TextInputWidgetState extends State<TextInputWidget> {if (widget.popNavAfterSubmission) {Future.delayed(Duration(seconds: widget.alwaysShowSuccessState ? 1 : 0),- () => _popNavigatorStack(context),+ () {+ if (!mounted) return;+ _popNavigatorStack(context);+ },);}}diff --git a/mobile/apps/auth/lib/ui/home_page.dart b/mobile/apps/auth/lib/ui/home_page.dartindex b8f8f04bbb..46b34d0201 100644--- a/mobile/apps/auth/lib/ui/home_page.dart+++ b/mobile/apps/auth/lib/ui/home_page.dart@@ -130,6 +130,7 @@ class _HomePageState extends State<HomePage> {_triggerLogoutEvent = Bus.instance.on<TriggerLogoutEvent>().listen((event,) async {+ if (!mounted) return;await autoLogoutAlert(context);});@@ -223,7 +224,9 @@ class _HomePageState extends State<HomePage> {if (!isAuthSuccessful) return;+ if (!mounted) return;FocusScope.of(context).requestFocus();+ if (!mounted) return;await showChoiceActionSheet(context,title: l10n.deleteCodeTitle,@@ -421,7 +424,9 @@ class _HomePageState extends State<HomePage> {);if (!isAuthSuccessful) return;+ if (!mounted) return;FocusScope.of(context).requestFocus();+ if (!mounted) return;await showChoiceActionSheet(context,title: l10n.trashCode,@@ -474,6 +479,7 @@ class _HomePageState extends State<HomePage> {if (!isAuthSuccessful) return;_codeDisplayStore.clearSelection();+ if (!mounted) return;final Code? updatedCode = await Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) {@@ -497,6 +503,7 @@ class _HomePageState extends State<HomePage> {if (!isAuthSuccessful) return;_codeDisplayStore.clearSelection();+ if (!mounted) return;showShareDialog(context, code);}@@ -513,6 +520,7 @@ class _HomePageState extends State<HomePage> {.replaceAll('algorithm=sha256', 'algorithm=SHA256').replaceAll('algorithm=sha512', 'algorithm=SHA512');+ if (!mounted) return;await showDialog(context: context,builder: (BuildContext dialogContext) {@@ -1331,6 +1339,7 @@ class _HomePageState extends State<HomePage> {_isImportingFromGallery = true;try {+ if (!mounted) return;final GalleryImportResult? importResult = await pickCodeFromGallery(context,logger: _logger,@@ -1340,6 +1349,7 @@ class _HomePageState extends State<HomePage> {}final googleAuthCodes = importResult.googleAuthCodes;if (googleAuthCodes != null) {+ if (!mounted) return;final shouldImport = await confirmGoogleAuthImport(context,googleAuthCodes.length,@@ -1370,6 +1380,7 @@ class _HomePageState extends State<HomePage> {if (importedCodeCount > 0) {LocalBackupService.instance.triggerDailyBackupIfNeeded().ignore();}+ if (!mounted) return;await importSuccessDialog(context, importedCodeCount);}@@ -1424,9 +1435,11 @@ class _HomePageState extends State<HomePage> {final bool shouldShowLockScreen = await LockScreenSettings.instance.shouldShowLockScreen();if (shouldShowLockScreen) {+ if (!mounted) return;// Manual lock: do not auto-prompt Touch ID; wait for user tapawait AppLock.of(context)!.showManualLockScreen();} else {+ if (!mounted) return;await showDialogWidget(context: context,title: context.l10n.appLockNotEnabled,@@ -2013,8 +2026,10 @@ class _HomePageState extends State<HomePage> {// Platform messages may fail, so we use a try/catch PlatformException.bool hadInitialLink = false;try {+ if (!mounted) return false;final initialLink = await _appLinks.getInitialLinkString();if (initialLink != null) {+ if (!mounted) return false;_handleDeeplink(context, initialLink);hadInitialLink = true;} else {@@ -2028,6 +2043,7 @@ class _HomePageState extends State<HomePage> {if (!kIsWeb && !Platform.isLinux) {_deepLinkSubscription = _appLinks.stringLinkStream.listen((link) {+ if (!mounted) return;_handleDeeplink(context, link);},onError: (err) {diff --git a/mobile/apps/auth/lib/ui/reorder_codes_page.dart b/mobile/apps/auth/lib/ui/reorder_codes_page.dartindex c41383d192..5689d2599f 100644--- a/mobile/apps/auth/lib/ui/reorder_codes_page.dart+++ b/mobile/apps/auth/lib/ui/reorder_codes_page.dart@@ -46,6 +46,7 @@ class _ReorderCodesPageState extends State<ReorderCodesPage> {onTap: () async {final hasSaved = await saveUpadedIndexes();if (hasSaved) {+ if (!context.mounted) return;Navigator.of(context).pop();}},diff --git a/mobile/apps/auth/lib/ui/scanner_page.dart b/mobile/apps/auth/lib/ui/scanner_page.dartindex bad386a720..7fb9e18816 100644--- a/mobile/apps/auth/lib/ui/scanner_page.dart+++ b/mobile/apps/auth/lib/ui/scanner_page.dart@@ -317,7 +317,9 @@ class ScannerPageState extends State<ScannerPage> {});bool shouldResumeCamera = true;try {+ if (!mounted) return;await controller?.pause();+ if (!mounted) return;final GalleryImportResult? importResult = await pickCodeFromGallery(context,logger: _logger,@@ -327,6 +329,7 @@ class ScannerPageState extends State<ScannerPage> {}final googleAuthCodes = importResult.googleAuthCodes;if (googleAuthCodes != null) {+ if (!mounted) return;final shouldImport = await confirmGoogleAuthImport(context,googleAuthCodes.length,diff --git a/mobile/apps/auth/lib/ui/settings/about_section_widget.dart b/mobile/apps/auth/lib/ui/settings/about_section_widget.dartindex 9fd28c4fb4..ac5b89cccc 100644--- a/mobile/apps/auth/lib/ui/settings/about_section_widget.dart+++ b/mobile/apps/auth/lib/ui/settings/about_section_widget.dart@@ -69,6 +69,7 @@ class AboutSectionWidget extends StatelessWidget {.shouldUpdate();await dialog.hide();if (shouldUpdate) {+ if (!context.mounted) return;// ignore: unawaited_futuresshowDialog(context: context,@@ -80,6 +81,7 @@ class AboutSectionWidget extends StatelessWidget {barrierColor: Colors.black.withValues(alpha: 0.85),);} else {+ if (!context.mounted) return;showShortToast(context,context.l10n.youAreOnTheLatestVersion,diff --git a/mobile/apps/auth/lib/ui/settings/account_section_widget.dart b/mobile/apps/auth/lib/ui/settings/account_section_widget.dartindex e4dfc05b4f..1ad6f90060 100644--- a/mobile/apps/auth/lib/ui/settings/account_section_widget.dart+++ b/mobile/apps/auth/lib/ui/settings/account_section_widget.dart@@ -45,6 +45,7 @@ class AccountSectionWidget extends StatelessWidget {final hasAuthenticated = await LocalAuthenticationService.instance.requestLocalAuthentication(context, l10n.authToChangeYourEmail);if (hasAuthenticated) {+ if (!context.mounted) return;// ignore: unawaited_futuresshowChangeEmailDialog(context);}@@ -63,6 +64,7 @@ class AccountSectionWidget extends StatelessWidget {l10n.authToChangeYourPassword,);if (hasAuthenticated) {+ if (!context.mounted) return;// ignore: unawaited_futuresNavigator.of(context).push(MaterialPageRoute(@@ -91,6 +93,7 @@ class AccountSectionWidget extends StatelessWidget {l10n.authToViewYourRecoveryKey,);if (hasAuthenticated) {+ if (!context.mounted) return;String recoveryKey;try {recoveryKey = CryptoUtil.bin2hex(diff --git a/mobile/apps/auth/lib/ui/settings/data/data_section_widget.dart b/mobile/apps/auth/lib/ui/settings/data/data_section_widget.dartindex cec5bbca5e..9b985e5ed5 100644--- a/mobile/apps/auth/lib/ui/settings/data/data_section_widget.dart+++ b/mobile/apps/auth/lib/ui/settings/data/data_section_widget.dart@@ -70,6 +70,7 @@ class DataSectionWidget extends StatelessWidget {.instance.getDuplicateCodes();if (duplicateCodes.isEmpty) {+ if (!context.mounted) return;unawaited(showChoiceDialog(context,@@ -81,6 +82,7 @@ class DataSectionWidget extends StatelessWidget {);return;}+ if (!context.mounted) return;await routeToPage(context,DuplicateCodePage(duplicateCodes: duplicateCodes),diff --git a/mobile/apps/auth/lib/ui/settings/data/duplicate_code_page.dart b/mobile/apps/auth/lib/ui/settings/data/duplicate_code_page.dartindex de34c785c2..863cfafb5a 100644--- a/mobile/apps/auth/lib/ui/settings/data/duplicate_code_page.dart+++ b/mobile/apps/auth/lib/ui/settings/data/duplicate_code_page.dart@@ -200,9 +200,11 @@ class _DuplicateCodePageState extends State<DuplicateCodePage> {if (!isAuthSuccessful) {return;}+ if (!mounted) return;FocusScope.of(context).requestFocus();final l10n = context.l10n;final String message = "Are you sure you want to trash $itemCount items?";+ if (!mounted) return;await showChoiceActionSheet(context,title: l10n.deleteDuplicates,@@ -211,6 +213,7 @@ class _DuplicateCodePageState extends State<DuplicateCodePage> {isCritical: true,firstButtonOnTap: () async {try {+ if (!mounted) return;for (int idx = 0; idx < _duplicateCodes.length; idx++) {if (selectedGrids.contains(idx)) {final List<Code> codes = _duplicateCodes[idx].codes;@@ -223,6 +226,7 @@ class _DuplicateCodePageState extends State<DuplicateCodePage> {}}}+ if (!mounted) return;Navigator.of(context).pop();} catch (e) {_logger.severe('Failed to trash duplicate codes: ${e.toString()}');diff --git a/mobile/apps/auth/lib/ui/settings/data/export_widget.dart b/mobile/apps/auth/lib/ui/settings/data/export_widget.dartindex bb2ae4ff26..548b7024f5 100644--- a/mobile/apps/auth/lib/ui/settings/data/export_widget.dart+++ b/mobile/apps/auth/lib/ui/settings/data/export_widget.dart@@ -50,6 +50,7 @@ Future<void> handleExportClick(BuildContext context) async {],);if (result?.action != null && result!.action != ButtonAction.cancel) {+ if (!context.mounted) return;if (result.action == ButtonAction.first) {await _requestForEncryptionPassword(context);} else if (result.action == ButtonAction.second) {@@ -74,13 +75,16 @@ Future<void> _requestForEncryptionPassword(alwaysShowSuccessState: false,onSubmit: (String password) async {if (password.isEmpty || password.length < 4) {+ if (!context.mounted) return;showToast(context, "Password must be at least 4 characters long.");Future.delayed(const Duration(seconds: 0), () {+ if (!context.mounted) return;_requestForEncryptionPassword(context, password: password);});return;}if (password.isNotEmpty) {+ if (!context.mounted) return;try {final kekSalt = CryptoUtil.getSaltToDeriveKey();final derivedKeyResult = await CryptoUtil.deriveSensitiveKey(@@ -105,6 +109,7 @@ Future<void> _requestForEncryptionPassword(salt: CryptoUtil.bin2base64(kekSalt),),);+ if (!context.mounted) return;// get json value of dataawait _exportCodes(context,@@ -113,6 +118,7 @@ Future<void> _requestForEncryptionPassword("json",);} catch (e) {+ if (!context.mounted) return;showToast(context, "Error while exporting codes.");}}@@ -131,11 +137,14 @@ Future<void> _showExportWarningDialog(BuildContext context, String type) async {);if (result?.action == ButtonAction.first) {+ if (!context.mounted) return;if (type == "html") {final data = await generateHtml(context);+ if (!context.mounted) return;await _exportCodes(context, data, "plainhtml", type);} else {final data = await _getAuthDataForExport();+ if (!context.mounted) return;await _exportCodes(context, data, "plaintext", type);}}@@ -155,9 +164,10 @@ Future<void> _exportCodes(if (!hasAuthenticated) {return;}- Future.delayed(- const Duration(milliseconds: 1200),- () async => await auth_share.shareDialog(+ if (!context.mounted) return;+ Future.delayed(const Duration(milliseconds: 1200), () async {+ if (!context.mounted) return;+ await auth_share.shareDialog(context,context.l10n.exportCodes,saveAction: () async {@@ -176,6 +186,7 @@ Future<void> _exportCodes(await codeFile.delete();}codeFile.writeAsStringSync(fileContent);+ if (!context.mounted) return;final Size size = MediaQuery.of(context).size;await SharePlus.instance.share(ShareParams(@@ -194,8 +205,8 @@ Future<void> _exportCodes(}});},- ),- );+ );+ });}Future<String> _getAuthDataForExport() async {diff --git a/mobile/apps/auth/lib/ui/settings/data/html_export.dart b/mobile/apps/auth/lib/ui/settings/data/html_export.dartindex ad9c1dcff1..2d5d105cab 100644--- a/mobile/apps/auth/lib/ui/settings/data/html_export.dart+++ b/mobile/apps/auth/lib/ui/settings/data/html_export.dart@@ -47,7 +47,7 @@ Future<String> generateQRImageBase64(String data) async {return base64Encode(pngBytes);}-Future<String> generateOTPEntryHtml(Code code, BuildContext context) async {+Future<String> generateOTPEntryHtml(Code code) async {// Capitalize algorithm for Google Authenticator compatibility in QR codesfinal qrData = code.rawData.replaceAll('algorithm=Algorithm.', 'algorithm=')@@ -90,7 +90,7 @@ Future<String> generateHtml(BuildContext context) async {for (final code in allCodes) {if (code.hasError) continue;- final entry = await generateOTPEntryHtml(code, context);+ final entry = await generateOTPEntryHtml(code);enteries.add(entry);}diff --git a/mobile/apps/auth/lib/ui/settings/data/import/aegis_import.dart b/mobile/apps/auth/lib/ui/settings/data/import/aegis_import.dartindex 119c667f71..5300d2ff2a 100644--- a/mobile/apps/auth/lib/ui/settings/data/import/aegis_import.dart+++ b/mobile/apps/auth/lib/ui/settings/data/import/aegis_import.dart@@ -48,6 +48,7 @@ Future<void> showAegisImportInstruction(BuildContext context) async {],);if (result?.action != null && result!.action != ButtonAction.cancel) {+ if (!context.mounted) return;if (result.action == ButtonAction.first) {await _pickAegisJsonFile(context);} else {}@@ -62,21 +63,25 @@ Future<void> _pickAegisJsonFile(BuildContext context) async {if (result == null) {return;}+ if (!context.mounted) return;final ProgressDialog progressDialog = createProgressDialog(context,l10n.pleaseWait,);await progressDialog.show();try {+ if (!context.mounted) return;String path = result.files.single.path!;int? count = await _processAegisExportFile(context, path, progressDialog);await progressDialog.hide();if (count != null) {+ if (!context.mounted) return;await importSuccessDialog(context, count);}} catch (e, s) {Logger('AegisImport').severe('exception while processing for aegis', e, s);await progressDialog.hide();+ if (!context.mounted) return;await showErrorDialog(context,context.l10n.sorry,@@ -95,9 +100,11 @@ Future<int?> _processAegisExportFile(final isEncrypted = decodedJson['header']['slots'] != null;Map? aegisDB;if (isEncrypted) {+ if (!context.mounted) return null;await dialog.hide();String? password;try {+ if (!context.mounted) return null;await showTextInputDialog(context,title: context.l10n.enterPasswordToAegisVault,@@ -120,6 +127,7 @@ Future<int?> _processAegisExportFile().warning("exception while decrypting aegis vault", e, s);await dialog.hide();if (password != null) {+ if (!context.mounted) return null;await showErrorDialog(context,context.l10n.failedToDecryptAegisVault,diff --git a/mobile/apps/auth/lib/ui/settings/data/import/andotp_import.dart b/mobile/apps/auth/lib/ui/settings/data/import/andotp_import.dartindex edd512f91b..b679ef50c2 100644--- a/mobile/apps/auth/lib/ui/settings/data/import/andotp_import.dart+++ b/mobile/apps/auth/lib/ui/settings/data/import/andotp_import.dart@@ -45,6 +45,7 @@ Future<void> showAndOTPImportInstruction(BuildContext context) async {],);if (result?.action != null && result!.action != ButtonAction.cancel) {+ if (!context.mounted) return;if (result.action == ButtonAction.first) {await _pickAndOTPFile(context);}@@ -62,21 +63,25 @@ Future<void> _pickAndOTPFile(BuildContext context) async {if (result == null) {return;}+ if (!context.mounted) return;final ProgressDialog progressDialog = createProgressDialog(context,l10n.pleaseWait,);try {+ if (!context.mounted) return;String path = result.files.single.path!;final count = await _processAndOTPFile(context, path, progressDialog);await progressDialog.hide();if (count != null) {+ if (!context.mounted) return;await importSuccessDialog(context, count);}} catch (e, s) {_logger.severe('Exception while processing andOTP import', e, s);await progressDialog.hide();+ if (!context.mounted) return;await showErrorDialog(context,l10n.sorry,@@ -109,6 +114,7 @@ Future<int?> _processAndOTPFile(entries = jsonDecode(jsonString) as List<dynamic>;await dialog.show();} catch (e) {+ if (!context.mounted) return null;// If JSON parsing fails, assume it's encryptedString? password;try {@@ -134,6 +140,7 @@ Future<int?> _processAndOTPFile(_logger.warning("Exception while decrypting andOTP backup", e, s);await dialog.hide();if (password != null) {+ if (!context.mounted) return null;await showErrorDialog(context,context.l10n.failedToDecryptAndOTPBackup,diff --git a/mobile/apps/auth/lib/ui/settings/data/import/bitwarden_import.dart b/mobile/apps/auth/lib/ui/settings/data/import/bitwarden_import.dartindex 86eadcbfb9..b7cbb4bb3f 100644--- a/mobile/apps/auth/lib/ui/settings/data/import/bitwarden_import.dart+++ b/mobile/apps/auth/lib/ui/settings/data/import/bitwarden_import.dart@@ -41,6 +41,7 @@ Future<void> showBitwardenImportInstruction(BuildContext context) async {],);if (result?.action != null && result!.action != ButtonAction.cancel) {+ if (!context.mounted) return;if (result.action == ButtonAction.first) {await _pickBitwardenJsonFile(context);}@@ -53,18 +54,22 @@ Future<void> _pickBitwardenJsonFile(BuildContext context) async {if (result == null) {return;}+ if (!context.mounted) return;final progressDialog = createProgressDialog(context, l10n.pleaseWait);await progressDialog.show();try {+ if (!context.mounted) return;String path = result.files.single.path!;int? count = await _processBitwardenExportFile(context, path);await progressDialog.hide();if (count != null) {+ if (!context.mounted) return;await importSuccessDialog(context, count);}} catch (e, s) {Logger("BitwardenImport").severe('Failed to import', e, s);await progressDialog.hide();+ if (!context.mounted) return;await showErrorDialog(context,context.l10n.sorry,diff --git a/mobile/apps/auth/lib/ui/settings/data/import/encrypted_ente_import.dart b/mobile/apps/auth/lib/ui/settings/data/import/encrypted_ente_import.dartindex f9b1533751..3380fc9445 100644--- a/mobile/apps/auth/lib/ui/settings/data/import/encrypted_ente_import.dart+++ b/mobile/apps/auth/lib/ui/settings/data/import/encrypted_ente_import.dart@@ -44,6 +44,7 @@ Future<void> showEncryptedImportInstruction(BuildContext context) async {],);if (result?.action != null && result!.action != ButtonAction.cancel) {+ if (!context.mounted) return;if (result.action == ButtonAction.first) {await _pickEnteJsonFile(context);} else {}@@ -73,6 +74,7 @@ Future<void> _decryptExportData(}final progressDialog = createProgressDialog(context, l10n.pleaseWait);try {+ if (!context.mounted) return;await progressDialog.show();final derivedKey = await CryptoUtil.deriveKey(utf8.encode(password),@@ -89,6 +91,7 @@ Future<void> _decryptExportData();} catch (e, s) {Logger("encryptedImport").warning('failed to decrypt', e, s);+ if (!context.mounted) return;showToast(context, l10n.incorrectPasswordTitle);shouldRetry = true;await progressDialog.hide();@@ -112,16 +115,20 @@ Future<void> _decryptExportData(await progressDialog.hide();} catch (e, s) {await progressDialog.hide();+ if (!context.mounted) return;Logger("ExportWidget").severe(e, s);+ if (!context.mounted) return;showToast(context, "Error while exporting codes.");}},);if (shouldRetry) {+ if (!context.mounted) return;await _decryptExportData(context, enteAuthExport);return;}if (importedCodeCount != null) {+ if (!context.mounted) return;await importSuccessDialog(context, importedCodeCount!);}}@@ -133,14 +140,17 @@ Future<void> _pickEnteJsonFile(BuildContext context) async {}try {+ if (!context.mounted) return;final jsonString = await readPickedImportFileAsString(result.files.single.path!,);EnteAuthExport exportedData = EnteAuthExport.fromJson(jsonDecode(jsonString),);+ if (!context.mounted) return;await _decryptExportData(context, exportedData);} catch (e) {+ if (!context.mounted) return;await showErrorDialog(context,context.l10n.sorry,diff --git a/mobile/apps/auth/lib/ui/settings/data/import/google_auth_import.dart b/mobile/apps/auth/lib/ui/settings/data/import/google_auth_import.dartindex 86112449d8..ba0a0e81c2 100644--- a/mobile/apps/auth/lib/ui/settings/data/import/google_auth_import.dart+++ b/mobile/apps/auth/lib/ui/settings/data/import/google_auth_import.dart@@ -54,6 +54,7 @@ Future<void> showGoogleAuthInstruction(BuildContext context) async {return;}if (action == ButtonAction.first) {+ if (!context.mounted) return;final List<Code>? codes = await Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) {@@ -65,9 +66,11 @@ Future<void> showGoogleAuthInstruction(BuildContext context) async {return;}final importedCount = await importGoogleAuthCodes(codes);+ if (!context.mounted) return;// ignore: unawaited_futuresimportSuccessDialog(context, importedCount);} else if (action == ButtonAction.second) {+ if (!context.mounted) return;await _importGoogleAuthFromImage(context);}}@@ -82,6 +85,7 @@ Future<void> _importGoogleAuthFromImage(BuildContext context) async {}final codes = importResult.googleAuthCodes;if (codes == null || codes.isEmpty) {+ if (!context.mounted) return;await showErrorDialog(context,context.l10n.errorInvalidQRCode,@@ -89,11 +93,13 @@ Future<void> _importGoogleAuthFromImage(BuildContext context) async {);return;}+ if (!context.mounted) return;final shouldImport = await confirmGoogleAuthImport(context, codes.length);if (!shouldImport) {return;}final importedCount = await importGoogleAuthCodes(codes);+ if (!context.mounted) return;// ignore: unawaited_futuresimportSuccessDialog(context, importedCount);}diff --git a/mobile/apps/auth/lib/ui/settings/data/import/lastpass_import.dart b/mobile/apps/auth/lib/ui/settings/data/import/lastpass_import.dartindex 959495fe0d..59d30abc75 100644--- a/mobile/apps/auth/lib/ui/settings/data/import/lastpass_import.dart+++ b/mobile/apps/auth/lib/ui/settings/data/import/lastpass_import.dart@@ -40,6 +40,7 @@ Future<void> showLastpassImportInstruction(BuildContext context) async {],);if (result?.action != null && result!.action != ButtonAction.cancel) {+ if (!context.mounted) return;if (result.action == ButtonAction.first) {await _pickLastpassJsonFile(context);}@@ -52,18 +53,22 @@ Future<void> _pickLastpassJsonFile(BuildContext context) async {if (result == null) {return;}+ if (!context.mounted) return;final progressDialog = createProgressDialog(context, l10n.pleaseWait);await progressDialog.show();try {+ if (!context.mounted) return;String path = result.files.single.path!;int? count = await _processLastpassExportFile(context, path);await progressDialog.hide();if (count != null) {+ if (!context.mounted) return;await importSuccessDialog(context, count);}} catch (e, s) {Logger('LastPassImport').severe('exception while processing import', e, s);await progressDialog.hide();+ if (!context.mounted) return;await showErrorDialog(context,context.l10n.sorry,diff --git a/mobile/apps/auth/lib/ui/settings/data/import/plain_text_import.dart b/mobile/apps/auth/lib/ui/settings/data/import/plain_text_import.dartindex 199257edd7..eb95f889f2 100644--- a/mobile/apps/auth/lib/ui/settings/data/import/plain_text_import.dart+++ b/mobile/apps/auth/lib/ui/settings/data/import/plain_text_import.dart@@ -89,9 +89,11 @@ Future<void> _pickImportFile(BuildContext context) async {if (result == null) {return;}+ if (!context.mounted) return;final progressDialog = createProgressDialog(context, l10n.pleaseWait);await progressDialog.show();try {+ if (!context.mounted) return;final parsedCodes = [];final codes = await readPickedImportFileAsString(result.files.single.path!);@@ -125,9 +127,12 @@ Future<void> _pickImportFile(BuildContext context) async {}unawaited(AuthenticatorService.instance.onlineSync());await progressDialog.hide();+ if (!context.mounted) return;await importSuccessDialog(context, parsedCodes.length);} catch (e) {await progressDialog.hide();+ if (!context.mounted) return;+ if (!context.mounted) return;await showErrorDialog(context,context.l10n.sorry,diff --git a/mobile/apps/auth/lib/ui/settings/data/import/proton_import.dart b/mobile/apps/auth/lib/ui/settings/data/import/proton_import.dartindex 2154a537b1..c2e080630d 100644--- a/mobile/apps/auth/lib/ui/settings/data/import/proton_import.dart+++ b/mobile/apps/auth/lib/ui/settings/data/import/proton_import.dart@@ -41,6 +41,7 @@ Future<void> showProtonImportInstruction(BuildContext context) async {],);if (result?.action != null && result!.action != ButtonAction.cancel) {+ if (!context.mounted) return;if (result.action == ButtonAction.first) {await _pickProtonJsonFile(context);}@@ -56,12 +57,15 @@ Future<void> _pickProtonJsonFile(BuildContext context) async {return;}+ if (!context.mounted) return;final progressDialog = createProgressDialog(context, l10n.pleaseWait);try {+ if (!context.mounted) return;final path = result.files.single.path!;final count = await _processProtonExportFile(context, path, progressDialog);await progressDialog.hide();if (count != null) {+ if (!context.mounted) return;await importSuccessDialog(context, count);}} catch (e, s) {@@ -69,6 +73,7 @@ Future<void> _pickProtonJsonFile(BuildContext context) async {'ProtonImport',).severe('Exception while processing Proton import', e, s);await progressDialog.hide();+ if (!context.mounted) return;await showErrorDialog(context,context.l10n.sorry,@@ -88,7 +93,9 @@ Future<int?> _processProtonExportFile(try {decodedJson = decodeProtonExportJson(jsonString);} on FormatException {+ if (!context.mounted) return null;await dialog.hide();+ if (!context.mounted) return null;await showErrorDialog(context,context.l10n.invalidProtonExportTitle,@@ -98,7 +105,9 @@ Future<int?> _processProtonExportFile(}if (isEncryptedProtonExport(decodedJson)) {+ if (!context.mounted) return null;while (true) {+ if (!context.mounted) return null;final password = await _promptForProtonExportPassword(context);if (password == null) {return null;@@ -113,6 +122,7 @@ Future<int?> _processProtonExportFile(switch (decryptedJsonResult['status']) {case 'incorrect_password':await dialog.hide();+ if (!context.mounted) return null;await showErrorDialog(context,context.l10n.incorrectPasswordTitle,diff --git a/mobile/apps/auth/lib/ui/settings/data/import/raivo_plain_text_import.dart b/mobile/apps/auth/lib/ui/settings/data/import/raivo_plain_text_import.dartindex a995c3cf2e..544d1c2117 100644--- a/mobile/apps/auth/lib/ui/settings/data/import/raivo_plain_text_import.dart+++ b/mobile/apps/auth/lib/ui/settings/data/import/raivo_plain_text_import.dart@@ -40,6 +40,7 @@ Future<void> showRaivoImportInstruction(BuildContext context) async {],);if (result?.action != null && result!.action != ButtonAction.cancel) {+ if (!context.mounted) return;if (result.action == ButtonAction.first) {await _pickRaivoJsonFile(context);} else {}@@ -52,18 +53,22 @@ Future<void> _pickRaivoJsonFile(BuildContext context) async {if (result == null) {return;}+ if (!context.mounted) return;final progressDialog = createProgressDialog(context, l10n.pleaseWait);await progressDialog.show();try {+ if (!context.mounted) return;String path = result.files.single.path!;int? count = await _processRaivoExportFile(context, path);await progressDialog.hide();if (count != null) {+ if (!context.mounted) return;await importSuccessDialog(context, count);}} catch (e, s) {Logger("RaivoImport").severe('Failed to import', e, s);await progressDialog.hide();+ if (!context.mounted) return;await showErrorDialog(context,context.l10n.sorry,@@ -74,7 +79,9 @@ Future<void> _pickRaivoJsonFile(BuildContext context) async {Future<int?> _processRaivoExportFile(BuildContext context, String path) async {if (path.endsWith('.zip')) {+ if (!context.mounted) return null;await deletePickedImportFileIfAppOwned(path);+ if (!context.mounted) return null;await showErrorDialog(context,context.l10n.sorry,diff --git a/mobile/apps/auth/lib/ui/settings/data/import/two_fas_import.dart b/mobile/apps/auth/lib/ui/settings/data/import/two_fas_import.dartindex f3622b9c3b..a17aff831a 100644--- a/mobile/apps/auth/lib/ui/settings/data/import/two_fas_import.dart+++ b/mobile/apps/auth/lib/ui/settings/data/import/two_fas_import.dart@@ -44,6 +44,7 @@ Future<void> show2FasImportInstruction(BuildContext context) async {],);if (result?.action != null && result!.action != ButtonAction.cancel) {+ if (!context.mounted) return;if (result.action == ButtonAction.first) {await _pick2FasFile(context);} else {}@@ -58,21 +59,25 @@ Future<void> _pick2FasFile(BuildContext context) async {if (result == null) {return;}+ if (!context.mounted) return;final ProgressDialog progressDialog = createProgressDialog(context,l10n.pleaseWait,);try {+ if (!context.mounted) return;String path = result.files.single.path!;int? count = await _process2FasExportFile(context, path, progressDialog);await progressDialog.hide();if (count != null) {+ if (!context.mounted) return;await importSuccessDialog(context, count);}} catch (e, s) {Logger('2FASImport').severe('exception while processing import', e, s);await progressDialog.hide();+ if (!context.mounted) return;await showErrorDialog(context,context.l10n.sorry,@@ -90,7 +95,9 @@ Future<int?> _process2FasExportFile(final decodedJson = jsonDecode(jsonString);int version = (decodedJson['schemaVersion'] ?? 0) as int;if (version != 3 && version != 4) {+ if (!context.mounted) return null;await dialog.hide();+ if (!context.mounted) return null;// todo: extract strings for l10n. Use same naming format as in aegis// to avoid duplicate translation efforts.await showErrorDialog(@@ -114,6 +121,7 @@ Future<int?> _process2FasExportFile(// https://github.com/twofas/2fas-android/blob/e97f1a1040eafaed6d5284d54d33403dff215886/data/services/src/main/java/com/twofasapp/data/services/domain/BackupContent.kt#L39final isEncrypted = decodedJson['reference'] != null;if (isEncrypted) {+ if (!context.mounted) return null;String? password;try {await showTextInputDialog(@@ -136,6 +144,7 @@ Future<int?> _process2FasExportFile(Logger("2FASImport").warning("exception while decrypting backup", e, s);await dialog.hide();if (password != null) {+ if (!context.mounted) return null;await showErrorDialog(context,context.l10n.failedToDecrypt2FASExport,diff --git a/mobile/apps/auth/lib/ui/settings/data/local_backup/local_backup_experience.dart b/mobile/apps/auth/lib/ui/settings/data/local_backup/local_backup_experience.dartindex d2b8bfefe8..dc88eb44f4 100644--- a/mobile/apps/auth/lib/ui/settings/data/local_backup/local_backup_experience.dart+++ b/mobile/apps/auth/lib/ui/settings/data/local_backup/local_backup_experience.dart@@ -143,6 +143,7 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {if (Platform.isAndroid &&(_backupTreeUri == null || _backupTreeUri!.isEmpty) &&(_backupPath == null || _backupPath!.isEmpty)) {+ if (!mounted) return false;_showSnackBar(context.l10n.noDefaultBackupFolder);return false;}@@ -188,6 +189,7 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {'${Platform.operatingSystem}: No bookmark found, need to re-select backup location',);if (showSnackBar) {+ if (!mounted) return;_showSnackBar(context.l10n.selectFolderToContinue);}// Clear the path and prompt user to re-select@@ -212,6 +214,7 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {final success = await LocalBackupService.instance.triggerAutomaticBackup(isManual: true);if (showSnackBar) {+ if (!mounted) return;_showSnackBar(success? context.l10n.backupCreated@@ -221,6 +224,7 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {} catch (e) {_logger.severe('Manual backup failed with error: $e');if (showSnackBar) {+ if (!mounted) return;_showSnackBar(context.l10n.somethingWentWrongPleaseTryAgain);}}@@ -378,6 +382,7 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {return false;}await Configuration.instance.clearBackupPassword();+ if (!mounted) return false;_showSnackBar(context.l10n.backupPasswordCleared);return true;}@@ -566,6 +571,7 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {// Use our native picker that creates bookmark immediatelyfinal pickResult = await SecurityBookmarkService.instance.pickDirectoryAndCreateBookmark();+ if (!mounted) return false;if (pickResult != null) {if (_isInvalidIosPath(pickResult.path)) {_showSnackBar(context.l10n.iosOnMyDeviceNotSupported);@@ -585,6 +591,7 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {// On macOS, use DirUtils which creates a security-scoped bookmarkfinal picked = await DirUtils.instance.pickDirectory();if (picked != null && picked.path.isNotEmpty && picked.bookmark != null) {+ if (!mounted) return false;return _persistLocationWithBookmark(picked.path,picked.bookmark!,@@ -597,6 +604,7 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {// Other platforms (Windows, Linux, etc.)final picked = await DirUtils.instance.pickDirectory();if (picked != null && picked.path.isNotEmpty) {+ if (!mounted) return false;return _persistLocation(picked.path,successMessage: context.l10n.initialBackupCreated,@@ -712,6 +720,7 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {);if (saved) {} else if (requireSelection) {+ if (!mounted) return false;_showSnackBar(context.l10n.selectFolderToContinue);}return saved;@@ -721,9 +730,11 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {.pickDirectoryAndCreateBookmark();if (result != null) {if (_isInvalidIosPath(result.path)) {+ if (!mounted) return false;_showSnackBar(context.l10n.iosOnMyDeviceNotSupported);return false;}+ if (!mounted) return false;final saved = await _persistLocationWithBookmark(result.path,result.bookmark,@@ -733,6 +744,7 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {return saved;}if (requireSelection) {+ if (!mounted) return false;_showSnackBar(context.l10n.selectFolderToContinue);}return false;@@ -740,6 +752,7 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {// On macOS, use DirUtils which creates a security-scoped bookmarkfinal picked = await DirUtils.instance.pickDirectory();if (picked != null && picked.path.isNotEmpty && picked.bookmark != null) {+ if (!mounted) return false;final saved = await _persistLocationWithBookmark(picked.path,picked.bookmark!,@@ -749,6 +762,7 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {return saved;}if (requireSelection) {+ if (!mounted) return false;_showSnackBar(context.l10n.selectFolderToContinue);}return false;@@ -757,6 +771,7 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {final picked = await DirUtils.instance.pickDirectory();if (picked != null && picked.path.isNotEmpty) {+ if (!mounted) return false;final saved = await _persistLocation(picked.path,successMessage:@@ -772,6 +787,7 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {return saved;}if (requireSelection) {+ if (!mounted) return false;_showSnackBar(context.l10n.selectFolderToContinue);}return false;@@ -880,6 +896,7 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {}_logger.warning('All backup path options failed for: $path');+ if (!mounted) return false;_showSnackBar(context.l10n.noDefaultBackupFolder);return false;}@@ -922,6 +939,7 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {if (shouldTriggerBackup) {final backupSuccess = await LocalBackupService.instance.triggerAutomaticBackup(isManual: true);+ if (!mounted) return false;_showSnackBar(backupSuccess? (successMessage ?? context.l10n.locationUpdatedAndBackupCreated)@@ -934,6 +952,7 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {}return true;} catch (_) {+ if (!mounted) return false;_showSnackBar(context.l10n.noDefaultBackupFolder);return false;}diff --git a/mobile/apps/auth/lib/ui/settings/general_section_widget.dart b/mobile/apps/auth/lib/ui/settings/general_section_widget.dartindex 199a71dbe7..173ca05e64 100644--- a/mobile/apps/auth/lib/ui/settings/general_section_widget.dart+++ b/mobile/apps/auth/lib/ui/settings/general_section_widget.dart@@ -50,11 +50,13 @@ class _AdvancedSectionWidgetState extends State<AdvancedSectionWidget> {trailingIconIsMuted: true,onTap: () async {final locale = (await getLocale())!;+ if (!context.mounted) return;// ignore: unawaited_futuresauth_nav.routeToPage(context,LanguageSelectorPage(appSupportedLocales, (locale) async {await setLocale(locale);+ if (!context.mounted) return;App.setLocale(context, locale);}, locale),);@@ -110,6 +112,7 @@ class _AdvancedSectionWidgetState extends State<AdvancedSectionWidget> {!PreferenceService.instance.shouldHideCodes(),);if (PreferenceService.instance.shouldHideCodes()) {+ if (!context.mounted) return;showToast(context, context.l10n.doubleTapToViewHiddenCode);}setState(() {});diff --git a/mobile/apps/auth/lib/ui/settings/security_section_widget.dart b/mobile/apps/auth/lib/ui/settings/security_section_widget.dartindex c555db17be..26afb11e32 100644--- a/mobile/apps/auth/lib/ui/settings/security_section_widget.dart+++ b/mobile/apps/auth/lib/ui/settings/security_section_widget.dart@@ -118,6 +118,7 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {context.l10n.authToViewYourActiveSessions,);if (hasAuthenticated) {+ if (!context.mounted) return;// ignore: unawaited_futuresNavigator.of(context).push(MaterialPageRoute(@@ -159,12 +160,14 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {return;}}+ if (!context.mounted) return;final hasAuthenticated = await LocalAuthenticationService.instance.requestLocalAuthentication(context,context.l10n.authToChangeLockscreenSetting,);if (hasAuthenticated) {+ if (!context.mounted) return;await Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) {@@ -182,6 +185,7 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {Future<void> onPasskeyClick(BuildContext buildContext) async {try {+ if (!buildContext.mounted) return;final hasAuthenticated = await LocalAuthenticationService.instance.requestLocalAuthentication(context,@@ -204,19 +208,23 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {CryptoUtil.bin2base64(encryptionResult.nonce!),);}+ if (!buildContext.mounted) return;await PasskeyService.instance.openPasskeyPage(buildContext);} catch (e, s) {_logger.severe("failed to open passkey page", e, s);+ if (!mounted) return;await showGenericErrorDialog(context: context, error: e);}}Future<void> updateEmailMFA(bool enableEmailMFA) async {try {+ if (!context.mounted) return;final UserDetails details = await UserService.instance.getUserDetailsV2(memoryCount: false,);if (details.profileData?.canDisableEmailMFA == false) {+ if (!mounted) return;await routeToPage(context,RequestPasswordVerificationPage(@@ -231,6 +239,7 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {);}if (enableEmailMFA) {+ if (!mounted) return;await showChoiceActionSheet(context,title: context.l10n.warning,@@ -246,6 +255,7 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {await UserService.instance.updateEmailMFA(enableEmailMFA);}} catch (e) {+ if (!mounted) return;showToast(context, context.l10n.somethingWentWrongMessage);}}diff --git a/mobile/apps/auth/lib/ui/settings/support_section_widget.dart b/mobile/apps/auth/lib/ui/settings/support_section_widget.dartindex 50dc4db954..9dc0cfdf4f 100644--- a/mobile/apps/auth/lib/ui/settings/support_section_widget.dart+++ b/mobile/apps/auth/lib/ui/settings/support_section_widget.dart@@ -90,7 +90,9 @@ class _SupportSectionWidgetState extends State<SupportSectionWidget> {},onDoubleTap: () async {try {+ if (!context.mounted) return;final zipFilePath = await getZippedLogsFile(context);+ if (!context.mounted) return;await shareLogs(context, "[email protected]", zipFilePath);} catch (e) {Logger("SupportSectionWidget").severe("failed to export logs", e);diff --git a/mobile/apps/auth/lib/ui/settings_page.dart b/mobile/apps/auth/lib/ui/settings_page.dartindex 9370b1f5a9..f138bf0256 100644--- a/mobile/apps/auth/lib/ui/settings_page.dart+++ b/mobile/apps/auth/lib/ui/settings_page.dart@@ -104,13 +104,16 @@ class SettingsPage extends StatelessWidget {);if (result == null) return;if (result.action == ButtonAction.first) {+ if (!context.mounted) return;await handleExportClick(context);} else {+ if (!context.mounted) return;if (result.action == ButtonAction.second) {bool hasCodes = (await CodeStore.instance.getAllCodes()).where((element) => !element.hasError).isNotEmpty;if (hasCodes) {+ if (!context.mounted) return;final hasAuthenticated = await LocalAuthenticationService.instance.requestLocalAuthentication(@@ -121,6 +124,7 @@ class SettingsPage extends StatelessWidget {return;}}+ if (!context.mounted) return;await routeToPage(context, const OnboardingPage());}}diff --git a/mobile/apps/auth/lib/ui/share/code_share.dart b/mobile/apps/auth/lib/ui/share/code_share.dartindex 93caa2aa71..e279ae9c63 100644--- a/mobile/apps/auth/lib/ui/share/code_share.dart+++ b/mobile/apps/auth/lib/ui/share/code_share.dart@@ -85,7 +85,9 @@ class _ShareCodeDialogState extends State<ShareCodeDialog> {labelText: context.l10n.share,onTap: () async {try {+ if (!context.mounted) return;await shareCode(selectedValue);+ if (!context.mounted) return;Navigator.of(context).pop();} catch (e, s) {logger.severe('Failed to generate shared codes', e, s);@@ -120,6 +122,7 @@ class _ShareCodeDialogState extends State<ShareCodeDialog> {String url ='https://auth.ente.com/share?data=${_uint8ListToUrlSafeBase64(encResult.encryptedData!)}&header=${_uint8ListToUrlSafeBase64(encResult.header!)}#${_uint8ListToUrlSafeBase64(key)}';try {+ if (!mounted) return;await shareText(url, context: context);} catch (e) {logger.warning('Failed to share code: ${e.toString()}');diff --git a/mobile/apps/auth/lib/utils/email_util.dart b/mobile/apps/auth/lib/utils/email_util.dartindex 796eb75506..5e81754cbb 100644--- a/mobile/apps/auth/lib/utils/email_util.dart+++ b/mobile/apps/auth/lib/utils/email_util.dart@@ -82,21 +82,23 @@ Future<void> sendLogs(labelText: l10n.exportLogs,buttonAction: ButtonAction.third,onTap: () async {- Future.delayed(- const Duration(milliseconds: 200),- () => auth_share.shareDialog(+ Future.delayed(const Duration(milliseconds: 200), () {+ if (!context.mounted) return;+ auth_share.shareDialog(context,title,saveAction: () async {final zipFilePath = await getZippedLogsFile(context);+ if (!context.mounted) return;await exportLogs(context, zipFilePath);},sendAction: () async {final zipFilePath = await getZippedLogsFile(context);+ if (!context.mounted) return;await exportLogs(context, zipFilePath, true);},- ),- );+ );+ });},),ButtonWidget(@@ -196,21 +198,24 @@ Future<void> shareLogs(],);if (result?.action != null && result!.action == ButtonAction.second) {- Future.delayed(- const Duration(milliseconds: 200),- () => auth_share.shareDialog(+ if (!context.mounted) return;+ Future.delayed(const Duration(milliseconds: 200), () {+ if (!context.mounted) return;+ auth_share.shareDialog(context,context.l10n.exportLogs,saveAction: () async {final zipFilePath = await getZippedLogsFile(context);+ if (!context.mounted) return;await exportLogs(context, zipFilePath);},sendAction: () async {final zipFilePath = await getZippedLogsFile(context);+ if (!context.mounted) return;await exportLogs(context, zipFilePath, true);},- ),- );+ );+ });}}@@ -245,6 +250,7 @@ Future<void> sendEmail(String? body,}) async {try {+ if (!context.mounted) return;final String clientDebugInfo = await _clientInfo();final String subject0 = subject ?? '[Support]';final String body0 = (body ?? '') + clientDebugInfo;@@ -270,10 +276,12 @@ Future<void> sendEmail(throw Exception('Could not launch ${params.toString()}');}} else {+ if (!context.mounted) return;_showNoMailAppsDialog(context, to);}} catch (e) {_logger.severe("Failed to send email to $to", e);+ if (!context.mounted) return;_showNoMailAppsDialog(context, to);}}@@ -299,6 +307,7 @@ void _showNoMailAppsDialog(BuildContext context, String toEmail) {secondButtonLabel: l10n.ok,firstButtonOnTap: () async {await Clipboard.setData(ClipboardData(text: toEmail));+ if (!context.mounted) return;showShortToast(context, l10n.copied);},);diff --git a/mobile/apps/auth/lib/utils/gallery_import_util.dart b/mobile/apps/auth/lib/utils/gallery_import_util.dartindex ea27b67622..9a0a120586 100644--- a/mobile/apps/auth/lib/utils/gallery_import_util.dart+++ b/mobile/apps/auth/lib/utils/gallery_import_util.dart@@ -121,6 +121,7 @@ Future<GalleryImportResult?> pickCodeFromGallery(final l10n = context.l10n;try {+ if (!context.mounted) return null;final FilePickerResult? result = await FilePicker.platform.pickFiles(type: FileType.image,);@@ -146,6 +147,7 @@ Future<GalleryImportResult?> pickCodeFromGallery(return parseQrImportPayload(qrResult.content!);} catch (e, stackTrace) {logger?.severe('Error adding code from QR scan', e, stackTrace);+ if (!context.mounted) return null;await showErrorDialog(context,l10n.errorInvalidQRCode,@@ -156,6 +158,7 @@ Future<GalleryImportResult?> pickCodeFromGallery(}} else {logger?.warning('QR scan failed: ${qrResult.error}');+ if (!context.mounted) return null;await showErrorDialog(context,l10n.errorNoQRCode,@@ -166,6 +169,7 @@ Future<GalleryImportResult?> pickCodeFromGallery(}} catch (e, stackTrace) {logger?.severe('Failed to import from gallery', e, stackTrace);+ if (!context.mounted) return null;await showErrorDialog(context,l10n.errorGenericTitle,@@ -182,6 +186,7 @@ Future<GalleryImportResult?> pickCodeFromGallery(}} catch (e, stackTrace) {logger?.severe('Failed to import from gallery', e, stackTrace);+ if (!context.mounted) return null;await showErrorDialog(context,l10n.errorGenericTitle,diff --git a/mobile/apps/auth/lib/utils/toast_util.dart b/mobile/apps/auth/lib/utils/toast_util.dartindex a92be26ef9..caef095a16 100644--- a/mobile/apps/auth/lib/utils/toast_util.dart+++ b/mobile/apps/auth/lib/utils/toast_util.dart@@ -70,7 +70,9 @@ void showToast(// Default path (desktop)try {+ if (!context.mounted) return;await Fluttertoast.cancel();+ if (!context.mounted) return;await Fluttertoast.showToast(msg: message,toastLength: toastLength,@@ -81,6 +83,7 @@ void showToast(fontSize: 16.0,);} on MissingPluginException catch (_) {+ if (!context.mounted) return;final fToast = FToast()..init(context);final Widget baseToast = Container(padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),