π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
add context mounted check
AmanRajSinghMouryac6172fcdf537
diff --git a/mobile/packages/accounts/lib/pages/email_entry_page.dart b/mobile/packages/accounts/lib/pages/email_entry_page.dartindex b56cf013fd..ca10389803 100644--- a/mobile/packages/accounts/lib/pages/email_entry_page.dart+++ b/mobile/packages/accounts/lib/pages/email_entry_page.dart@@ -144,12 +144,14 @@ class _EmailEntryPageState extends State<EmailEntryPage> {await _referralSourceForSubmission(),);await UserService.instance.sendOtt(- context,+ context.mounted ? context : null,_email!,isCreateAccountScreen: true,purpose: "signup",);- FocusScope.of(context).unfocus();+ if (context.mounted) {+ FocusScope.of(context).unfocus();+ }},),],diff --git a/mobile/packages/accounts/lib/pages/login_page.dart b/mobile/packages/accounts/lib/pages/login_page.dartindex b8ebaf8321..8cfd2a1902 100644--- a/mobile/packages/accounts/lib/pages/login_page.dart+++ b/mobile/packages/accounts/lib/pages/login_page.dart@@ -41,22 +41,26 @@ class _LoginPageState extends State<LoginPage> {}}if (attr != null && !isEmailVerificationEnabled) {- await Navigator.of(context).push(- MaterialPageRoute(- builder: (BuildContext context) {- return LoginPasswordVerificationPage(widget.config, attr!);- },- ),- );+ if (mounted) {+ await Navigator.of(context).push(+ MaterialPageRoute(+ builder: (BuildContext context) {+ return LoginPasswordVerificationPage(widget.config, attr!);+ },+ ),+ );+ }} else {await UserService.instance.sendOtt(- context,+ mounted ? context : null,_email!,isCreateAccountScreen: false,purpose: 'login',);}- FocusScope.of(context).unfocus();+ if (mounted) {+ FocusScope.of(context).unfocus();+ }}@overridediff --git a/mobile/packages/accounts/lib/pages/login_pwd_verification_page.dart b/mobile/packages/accounts/lib/pages/login_pwd_verification_page.dartindex 5fd827c294..d0b0e61329 100644--- a/mobile/packages/accounts/lib/pages/login_pwd_verification_page.dart+++ b/mobile/packages/accounts/lib/pages/login_pwd_verification_page.dart@@ -115,13 +115,16 @@ class _LoginPasswordVerificationPageStateawait dialog.show();try {await UserService.instance.verifyEmailViaPassword(- context,+ context.mounted ? context : null,widget.srpAttributes,password,dialog,);} on DioException catch (e, s) {await dialog.hide();+ if (!context.mounted) {+ return;+ }if (e.response != null && e.response!.statusCode == 401) {_logger.severe('server reject, failed verify SRP login', e, s);@@ -154,12 +157,15 @@ class _LoginPasswordVerificationPageState_logger.severe('loginKey derivation error', e, s);// LoginKey err, perform regular login via ott verificationawait UserService.instance.sendOtt(- context,+ context.mounted ? context : null,email!,isCreateAccountScreen: true,);return;} else if (e is KeyDerivationError) {+ if (!context.mounted) {+ return;+ }// device is not powerful enough to perform derive keyfinal result = await showAlertBottomSheet<bool>(context,@@ -177,7 +183,7 @@ class _LoginPasswordVerificationPageState);if (result == true) {await UserService.instance.sendOtt(- context,+ context.mounted ? context : null,email!,isResetPasswordScreen: true,);@@ -185,11 +191,13 @@ class _LoginPasswordVerificationPageStatereturn;} else {_logger.severe('unexpected error while verifying password', e, s);- await _showContactSupportDialog(- context,- title: context.strings.oops,- message: context.strings.verificationFailedPleaseTryAgain,- );+ if (context.mounted) {+ await _showContactSupportDialog(+ context,+ title: context.strings.oops,+ message: context.strings.verificationFailedPleaseTryAgain,+ );+ }}}}@@ -213,7 +221,7 @@ class _LoginPasswordVerificationPageState),],);- if (result == true) {+ if (result == true && context.mounted) {await sendLogs(context, "[email protected]", postShare: () {});}}@@ -355,9 +363,11 @@ class _LoginPasswordVerificationPageStateawait dialog.show();await widget.config.logout();await dialog.hide();- Navigator.of(- context,- ).popUntil((route) => route.isFirst);+ if (mounted) {+ Navigator.of(+ context,+ ).popUntil((route) => route.isFirst);+ }},child: Text(context.strings.changeEmail,diff --git a/mobile/packages/accounts/lib/pages/passkey_page.dart b/mobile/packages/accounts/lib/pages/passkey_page.dartindex aab12d32b9..184abb01ce 100644--- a/mobile/packages/accounts/lib/pages/passkey_page.dart+++ b/mobile/packages/accounts/lib/pages/passkey_page.dart@@ -70,23 +70,35 @@ class _PasskeyPageState extends State<PasskeyPage> {widget.sessionID,);} on PassKeySessionNotVerifiedError {- showToast(context, context.strings.passKeyPendingVerification);+ if (mounted) {+ showToast(context, context.strings.passKeyPendingVerification);+ }return;} on PassKeySessionExpiredError {+ if (!mounted) {+ return;+ }await showAlertBottomSheet(context,title: context.strings.loginSessionExpired,message: context.strings.loginSessionExpiredDetails,assetPath: 'assets/warning-grey.png',);- Navigator.of(context).pop();+ if (mounted) {+ Navigator.of(context).pop();+ }return;} catch (e, s) {_logger.severe("failed to check status", e, s);- showGenericErrorDialog(context: context, error: e).ignore();+ if (mounted) {+ showGenericErrorDialog(context: context, error: e).ignore();+ }return;}- await UserService.instance.onPassKeyVerified(context, response);+ await UserService.instance.onPassKeyVerified(+ mounted ? context : null,+ response,+ );}Future<void> _handleDeeplink(String? link) async {@@ -118,13 +130,18 @@ class _PasskeyPageState extends State<PasskeyPage> {}final res = utf8.decode(base64.decode(base64String));final json = jsonDecode(res) as Map<String, dynamic>;- await UserService.instance.onPassKeyVerified(context, json);+ await UserService.instance.onPassKeyVerified(+ mounted ? context : null,+ json,+ );} else {_logger.info('ignored deeplink: $link mounted $mounted');}} catch (e, s) {_logger.severe('passKey: failed to handle deeplink', e, s);- showGenericErrorDialog(context: context, error: e).ignore();+ if (mounted) {+ showGenericErrorDialog(context: context, error: e).ignore();+ }}}@@ -203,7 +220,9 @@ class _PasskeyPageState extends State<PasskeyPage> {await checkStatus();} catch (e) {debugPrint('failed to check status %e');- showGenericErrorDialog(context: context, error: e).ignore();+ if (mounted) {+ showGenericErrorDialog(context: context, error: e).ignore();+ }}},),diff --git a/mobile/packages/accounts/lib/pages/password_entry_page.dart b/mobile/packages/accounts/lib/pages/password_entry_page.dartindex a5a63ceb74..8304d04d26 100644--- a/mobile/packages/accounts/lib/pages/password_entry_page.dart+++ b/mobile/packages/accounts/lib/pages/password_entry_page.dart@@ -430,11 +430,13 @@ class _PasswordEntryPageState extends State<PasswordEntryPage> {if (logOutFromOthers == null) {return;}- final dialog = createProgressDialog(- context,- context.strings.generatingEncryptionKeys,- );- await dialog.show();+ final dialog = mounted+ ? createProgressDialog(+ context,+ context.strings.generatingEncryptionKeys,+ )+ : null;+ await dialog?.show();try {final result = await widget.config.getAttributesForNewPassword(_passwordController1.text,@@ -444,17 +446,21 @@ class _PasswordEntryPageState extends State<PasswordEntryPage> {result.item2,logoutOtherDevices: logOutFromOthers,);- await dialog.hide();- showShortToast(context, context.strings.passwordChangedSuccessfully);- Navigator.of(context).pop();- if (widget.mode == PasswordEntryMode.reset) {- Navigator.of(context).popUntil((route) => route.isFirst);+ await dialog?.hide();+ if (mounted) {+ showShortToast(context, context.strings.passwordChangedSuccessfully);+ Navigator.of(context).pop();+ if (widget.mode == PasswordEntryMode.reset) {+ Navigator.of(context).popUntil((route) => route.isFirst);+ }}} catch (e, s) {_logger.severe("Failed to change password", e, s);- await dialog.hide();- // ignore: unawaited_futures- showGenericErrorDialog(context: context, error: e);+ await dialog?.hide();+ if (mounted) {+ // ignore: unawaited_futures+ showGenericErrorDialog(context: context, error: e);+ }}}@@ -526,30 +532,36 @@ class _PasswordEntryPageState extends State<PasswordEntryPage> {final result = await widget.config.generateKey(password);widget.config.resetVolatilePassword();await dialog.hide();+ if (!mounted) {+ return;+ }onDone() async {- final dialog = createProgressDialog(- context,- context.strings.pleaseWait,- );- await dialog.show();+ final dialog = mounted+ ? createProgressDialog(context, context.strings.pleaseWait)+ : null;+ await dialog?.show();try {await UserService.instance.setAttributes(result);- await dialog.hide();+ await dialog?.hide();widget.config.resetVolatilePassword();- // ignore: unawaited_futures- Navigator.of(context).pushAndRemoveUntil(- MaterialPageRoute(- builder: (BuildContext context) {- return widget.homePage;- },- ),- (route) => false,- );+ if (mounted) {+ // ignore: unawaited_futures+ Navigator.of(context).pushAndRemoveUntil(+ MaterialPageRoute(+ builder: (BuildContext context) {+ return widget.homePage;+ },+ ),+ (route) => false,+ );+ }} catch (e, s) {_logger.severe("Failed to configure account", e, s);- await dialog.hide();- // ignore: unawaited_futures- showGenericErrorDialog(context: context, error: e);+ await dialog?.hide();+ if (mounted) {+ // ignore: unawaited_futures+ showGenericErrorDialog(context: context, error: e);+ }}}@@ -569,6 +581,9 @@ class _PasswordEntryPageState extends State<PasswordEntryPage> {} catch (e) {_logger.severe(e);await dialog.hide();+ if (!mounted) {+ return;+ }if (e is UnsupportedError) {// ignore: unawaited_futuresshowAlertBottomSheet(diff --git a/mobile/packages/accounts/lib/pages/password_reentry_page.dart b/mobile/packages/accounts/lib/pages/password_reentry_page.dartindex 6d81a923c2..a26f60e46d 100644--- a/mobile/packages/accounts/lib/pages/password_reentry_page.dart+++ b/mobile/packages/accounts/lib/pages/password_reentry_page.dart@@ -120,6 +120,9 @@ class _PasswordReentryPageState extends State<PasswordReentryPage> {} on KeyDerivationError catch (e, s) {_logger.severe("Password verification failed", e, s);await dialog.hide();+ if (!mounted) {+ return;+ }final result = await showAlertBottomSheet<bool>(context,@@ -135,7 +138,7 @@ class _PasswordReentryPageState extends State<PasswordReentryPage> {),],);- if (result == true) {+ if (result == true && mounted) {// ignore: unawaited_futuresNavigator.of(context).push(MaterialPageRoute(@@ -149,6 +152,9 @@ class _PasswordReentryPageState extends State<PasswordReentryPage> {} catch (e, s) {_logger.severe("Password verification failed", e, s);await dialog.hide();+ if (!mounted) {+ return;+ }final result = await showAlertBottomSheet<bool>(context,@@ -164,23 +170,25 @@ class _PasswordReentryPageState extends State<PasswordReentryPage> {),],);- if (result == true) {+ if (result == true && mounted) {await sendLogs(context, "[email protected]", postShare: () {});}return;}widget.config.resetVolatilePassword();await dialog.hide();- unawaited(- Navigator.of(context).pushAndRemoveUntil(- MaterialPageRoute(- builder: (BuildContext context) {- return widget.homePage;- },+ if (mounted) {+ unawaited(+ Navigator.of(context).pushAndRemoveUntil(+ MaterialPageRoute(+ builder: (BuildContext context) {+ return widget.homePage;+ },+ ),+ (route) => false,),- (route) => false,- ),- );+ );+ }}Future<void> _registerSRPForExistingUsers(Uint8List key) async {@@ -322,9 +330,11 @@ class _PasswordReentryPageState extends State<PasswordReentryPage> {await dialog.show();await widget.config.logout();await dialog.hide();- Navigator.of(- context,- ).popUntil((route) => route.isFirst);+ if (mounted) {+ Navigator.of(+ context,+ ).popUntil((route) => route.isFirst);+ }},child: Text(context.strings.changeEmail,