From e1f081105ab32efd6773c8d883196815a762cc9c Mon Sep 17 00:00:00 2001 From: Brandon Vandegrift <798832-bmv437@users.noreply.gitlab.com> Date: Thu, 3 Apr 2025 14:27:56 -0400 Subject: [PATCH] Fix routing to home after initial account creation --- lib/account_manager/views/new_account_page.dart | 13 ++++++++++--- .../views/show_recovery_key_page.dart | 15 +++++++++++---- lib/router/cubits/router_cubit.dart | 15 ++++++--------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/lib/account_manager/views/new_account_page.dart b/lib/account_manager/views/new_account_page.dart index a739094..07034df 100644 --- a/lib/account_manager/views/new_account_page.dart +++ b/lib/account_manager/views/new_account_page.dart @@ -63,10 +63,13 @@ class _NewAccountPageState extends WindowSetupState { return false; } + final isFirstAccount = + AccountRepository.instance.getLocalAccounts().isEmpty; + final writableSuperIdentity = await AccountRepository.instance .createWithNewSuperIdentity(accountSpec); GoRouterHelper(context).pushReplacement('/new_account/recovery_key', - extra: [writableSuperIdentity, accountSpec.name]); + extra: [writableSuperIdentity, accountSpec.name, isFirstAccount]); return true; } finally { @@ -92,11 +95,15 @@ class _NewAccountPageState extends WindowSetupState { return StyledScaffold( appBar: DefaultAppBar( title: Text(translate('new_account_page.titlebar')), - leading: Navigator.canPop(context) + leading: GoRouterHelper(context).canPop() ? IconButton( icon: const Icon(Icons.arrow_back), onPressed: () { - Navigator.pop(context); + if (GoRouterHelper(context).canPop()) { + GoRouterHelper(context).pop(); + } else { + GoRouterHelper(context).go('/'); + } }, ) : null, diff --git a/lib/account_manager/views/show_recovery_key_page.dart b/lib/account_manager/views/show_recovery_key_page.dart index acbb3f3..bf44dd7 100644 --- a/lib/account_manager/views/show_recovery_key_page.dart +++ b/lib/account_manager/views/show_recovery_key_page.dart @@ -25,15 +25,18 @@ class ShowRecoveryKeyPage extends StatefulWidget { const ShowRecoveryKeyPage( {required WritableSuperIdentity writableSuperIdentity, required String name, + required bool isFirstAccount, super.key}) : _writableSuperIdentity = writableSuperIdentity, - _name = name; + _name = name, + _isFirstAccount = isFirstAccount; @override State createState() => _ShowRecoveryKeyPageState(); final WritableSuperIdentity _writableSuperIdentity; final String _name; + final bool _isFirstAccount; } class _ShowRecoveryKeyPageState extends WindowSetupState { @@ -248,9 +251,13 @@ class _ShowRecoveryKeyPageState extends WindowSetupState { child: ElevatedButton( onPressed: () { if (context.mounted) { - Navigator.canPop(context) - ? GoRouterHelper(context).pop() - : GoRouterHelper(context).go('/'); + if (widget._isFirstAccount) { + GoRouterHelper(context).go('/'); + } else { + GoRouterHelper(context).canPop() + ? GoRouterHelper(context).pop() + : GoRouterHelper(context).go('/'); + } } }, child: Text(translate('button.finish')).paddingAll(8)) diff --git a/lib/router/cubits/router_cubit.dart b/lib/router/cubits/router_cubit.dart index 19af5e0..a15eb50 100644 --- a/lib/router/cubits/router_cubit.dart +++ b/lib/router/cubits/router_cubit.dart @@ -96,7 +96,8 @@ class RouterCubit extends Cubit { if (extra == null || extra is! List || extra[0] is! WritableSuperIdentity || - extra[1] is! String) { + extra[1] is! String || + extra[2] is! bool) { return '/'; } return null; @@ -107,7 +108,8 @@ class RouterCubit extends Cubit { return ShowRecoveryKeyPage( writableSuperIdentity: extra[0] as WritableSuperIdentity, - name: extra[1] as String); + name: extra[1] as String, + isFirstAccount: extra[2] as bool); }), ]), GoRoute( @@ -123,14 +125,8 @@ class RouterCubit extends Cubit { /// Redirects when our state changes String? redirect(BuildContext context, GoRouterState goRouterState) { - // No matter where we are, if there's not - switch (goRouterState.matchedLocation) { - case '/': - if (!state.hasAnyAccount) { - return '/new_account'; - } - return null; + // We can go to any of these routes without an account. case '/new_account': return null; case '/new_account/recovery_key': @@ -139,6 +135,7 @@ class RouterCubit extends Cubit { return null; case '/developer': return null; + // Otherwise, if there's no account, we need to go to the new account page. default: return state.hasAnyAccount ? null : '/new_account'; }