Skip to content

Commit

Permalink
The user was stuck in the onboarding (openfoodfacts#5723)
Browse files Browse the repository at this point in the history
  • Loading branch information
g123k authored Oct 21, 2024
1 parent cfa5dae commit a4b3632
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
12 changes: 10 additions & 2 deletions packages/smooth_app/lib/pages/navigator/app_navigator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,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);
}
Expand Down Expand Up @@ -286,7 +293,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) {
Expand Down Expand Up @@ -421,7 +428,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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,23 @@ class OnboardingFlowNavigator {
static final List<OnboardingPage> _historyOnboardingNav = <OnboardingPage>[];

Future<void> navigateToPage(BuildContext context, OnboardingPage page) async {
_userPreferences.setLastVisitedOnboardingPage(page);
await _userPreferences.setLastVisitedOnboardingPage(page);
_historyOnboardingNav.add(page);

final MaterialPageRoute<void> route = MaterialPageRoute<void>(
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<void> route = MaterialPageRoute<void>(
builder: (BuildContext context) => page.getPageWidget(context),
);
await Navigator.of(context).push<void>(route);
}
}
Expand Down

0 comments on commit a4b3632

Please sign in to comment.