Skip to content

Commit

Permalink
feat(app): use popUntil instead of going back
Browse files Browse the repository at this point in the history
  • Loading branch information
tamara-slosarek authored and tamslo committed Feb 6, 2025
1 parent 57ceed4 commit accbb87
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
27 changes: 22 additions & 5 deletions app/lib/common/utilities/routing_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,34 @@ DeepLink getInitialRoute() {
return DeepLink.path(getInitialRouteName());
}

void routeBackToContent(
StackRouter router,
{
bool popLogin = true,
// Dialogs or modal bottom sheets will have no route name
bool popNull = false,
}) {
final currentRoute = router.current.name;
bool keepRoute(Route route) {
final isSecureRoute = route.settings.name == SecureRoute.name;
final isLoginRoute = route.settings.name == LoginRoute.name;
final isCurrentRoute = route.settings.name == currentRoute;
final isNullRoute = route.settings.name == null;
var keepCurrentRoute = !isSecureRoute && !isCurrentRoute;
if (popLogin) keepCurrentRoute = keepCurrentRoute && !isLoginRoute;
if (popNull) keepCurrentRoute = keepCurrentRoute && !isNullRoute;
return keepCurrentRoute;
}
router.popUntil(keepRoute);
}

bool currentPathIsSecurePath(StackRouter router) {
return router.currentPath == secureRoutePath;
}

Future<void> routeBackAfterSecurePage(StackRouter router) async {
if (currentPathIsSecurePath(router)) {
if (router.canPop()) {
await router.maybePop();
} else {
await router.pushNamed(getInitialRouteName());
}
routeBackToContent(router, popLogin: false);
}
}

Expand Down
7 changes: 1 addition & 6 deletions app/lib/common/widgets/tutorial/tutorial_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,7 @@ class TutorialBuilder extends HookWidget {
onPressed: isFirstPage
? () {
initiateRouteBack();
final currentRoute = context.router.current.name;
context.router.popUntil(
(route) =>
route.settings.name != null &&
route.settings.name != currentRoute,
);
routeBackToContent(context.router, popNull: true);
}
: () => currentPageIndex.value = currentPageIndex.value - 1,
text: isFirstPage
Expand Down
4 changes: 2 additions & 2 deletions app/lib/onboarding/pages/onboarding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class OnboardingPage extends HookWidget {
size: OnboardingDimensions.iconSize,
color: Colors.white,
),
onPressed: () => context.router.back(),
onPressed: () => routeBackToContent(context.router),
)
),
Positioned.fill(
Expand Down Expand Up @@ -211,7 +211,7 @@ class OnboardingPage extends HookWidget {
onPressed: () async {
if (isLastPage) {
if (isRevisiting) {
context.router.back();
routeBackToContent(context.router);
} else {
MetaData.instance.onboardingDone = true;
await MetaData.save();
Expand Down

0 comments on commit accbb87

Please sign in to comment.