Fix navigation error when state is changed to denied at app first start [skip_ci]

OmarHatem committed Dec 3, 2022 at 23:34 UTC 11a5e9771197496ac08b72972daf25108c47707b
3 files changed +6 -6
lib/main.dart
+1 -1
@@ -261,7 +261,7 @@ class AppState extends State<App> with SingleTickerProviderStateMixin {
261 final statusBarColor = Colors.transparent;
262 final authenticationStore = getIt.get<AuthenticationStore>();
263 final initialRoute =
264 - authenticationStore.state == AuthenticationState.denied
264 + authenticationStore.state == AuthenticationState.uninitialized
265 ? Routes.disclaimer
266 : Routes.login;
267 final currentTheme = settingsStore.currentTheme;
lib/reactions/bootstrap.dart
+3 -3
@@ -22,9 +22,9 @@ Future<void> bootstrap(GlobalKey<NavigatorState> navigatorKey) async {
22 final currentWalletName = getIt
23 .get<SharedPreferences>()
24 .getString(PreferencesKey.currentWalletName);
25 - authenticationStore.state = currentWalletName == null
26 - ? AuthenticationState.denied
27 - : AuthenticationState.installed;
25 + if (currentWalletName != null) {
26 + authenticationStore.state = AuthenticationState.installed;
27 + }
28
29 startAuthenticationStateChange(authenticationStore, navigatorKey);
30 startCurrentWalletChangeReaction(
lib/reactions/on_authentication_state_change.dart
+2 -2
@@ -23,12 +23,12 @@ void startAuthenticationStateChange(AuthenticationStore authenticationStore,
23 }
24
25 if (state == AuthenticationState.allowed) {
26 - await navigatorKey.currentState?.pushNamedAndRemoveUntil(Routes.dashboard, (route) => false);
26 + await navigatorKey.currentState!.pushNamedAndRemoveUntil(Routes.dashboard, (route) => false);
27 return;
28 }
29
30 if (state == AuthenticationState.denied) {
31 - await navigatorKey.currentState?.pushNamedAndRemoveUntil(Routes.welcome, (_) => false);
31 + await navigatorKey.currentState!.pushNamedAndRemoveUntil(Routes.welcome, (_) => false);
32 return;
33 }
34 });