diff --git a/packages/smooth_app/lib/pages/navigator/app_navigator.dart b/packages/smooth_app/lib/pages/navigator/app_navigator.dart index 44c9086a5f7..d9cc68f8f44 100644 --- a/packages/smooth_app/lib/pages/navigator/app_navigator.dart +++ b/packages/smooth_app/lib/pages/navigator/app_navigator.dart @@ -73,6 +73,13 @@ class AppNavigator extends InheritedWidget { _router.router.pushReplacement(routeName, extra: extra); } + /// Remove all the screens from the stack + void clearStack() { + while (_router.router.canPop() == true) { + _router.router.pop(); + } + } + void pop([dynamic result]) { _router.router.pop(result); } @@ -287,7 +294,7 @@ class _SmoothGoRouter { externalLink = true; } } else if (path == _ExternalRoutes.MOBILE_APP_DOWNLOAD) { - return AppRoutes.HOME; + return AppRoutes.HOME(); } else if (path == _ExternalRoutes.GUIDE_NUTRISCORE_V2) { return AppRoutes.GUIDE_NUTRISCORE_V2; } else if (path == _ExternalRoutes.SIGNUP) { @@ -422,7 +429,8 @@ class AppRoutes { AppRoutes._(); // Home page (or walkthrough during the onboarding) - static String get HOME => _InternalAppRoutes.HOME_PAGE; + static String HOME({bool redraw = false}) => + '${_InternalAppRoutes.HOME_PAGE}?redraw:$redraw'; // Product details (a [Product] is mandatory in the extra) static String PRODUCT( diff --git a/packages/smooth_app/lib/pages/onboarding/onboarding_flow_navigator.dart b/packages/smooth_app/lib/pages/onboarding/onboarding_flow_navigator.dart index 2391b6abb1d..0fa723075c5 100644 --- a/packages/smooth_app/lib/pages/onboarding/onboarding_flow_navigator.dart +++ b/packages/smooth_app/lib/pages/onboarding/onboarding_flow_navigator.dart @@ -139,16 +139,23 @@ class OnboardingFlowNavigator { static final List _historyOnboardingNav = []; Future navigateToPage(BuildContext context, OnboardingPage page) async { - _userPreferences.setLastVisitedOnboardingPage(page); + await _userPreferences.setLastVisitedOnboardingPage(page); _historyOnboardingNav.add(page); - final MaterialPageRoute route = MaterialPageRoute( - builder: (BuildContext context) => page.getPageWidget(context), - ); + if (!context.mounted) { + return; + } if (page.isOnboardingComplete()) { - AppNavigator.of(context).pushReplacement(AppRoutes.HOME); + AppNavigator.of(context) + ..clearStack() + ..pushReplacement( + AppRoutes.HOME(redraw: true), + ); } else { + final MaterialPageRoute route = MaterialPageRoute( + builder: (BuildContext context) => page.getPageWidget(context), + ); await Navigator.of(context).push(route); } }