Skip to content

Commit

Permalink
feat(app): use pop to route back after secure page
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Feb 5, 2025
1 parent caae401 commit 2733d19
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PharMeApp extends StatelessWidget {
debugShowCheckedModeBanner: false,
routeInformationParser: _appRouter.defaultRouteParser(),
routerDelegate: _appRouter.delegate(
deepLinkBuilder: getInitialRoute,
deepLinkBuilder: (_) => getInitialRoute(),
navigatorObservers: () => [RemoveFocusOnNavigate()],
),
theme: PharMeTheme.light,
Expand Down
24 changes: 18 additions & 6 deletions app/lib/common/utilities/routing_utils.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
import '../../secure/module.dart';
import '../module.dart';

DeepLink getInitialRoute(_) {
String getInitialRouteName() {
final isLoggedIn = MetaData.instance.isLoggedIn ?? false;
final onboardingDone = MetaData.instance.onboardingDone ?? false;
final initialDrugSelectionDone =
MetaData.instance.initialDrugSelectionDone ?? false;
late String path;
path = !isLoggedIn
return !isLoggedIn
? '/login'
: !onboardingDone
? '/onboarding'
: !initialDrugSelectionDone
? '/drugselection'
: '/main';
return DeepLink.path(path);
}

bool currentPathIsSecurePath(AppRouter appRouter) {
return appRouter.currentPath == secureRoutePath;
DeepLink getInitialRoute() {
return DeepLink.path(getInitialRouteName());
}

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());
}
}
}

// Replace whole stack, see https://stackoverflow.com/a/73784156
Expand Down
2 changes: 1 addition & 1 deletion app/lib/common/widgets/lifecycle_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LifecycleObserver extends HookWidget {
Widget build(BuildContext context) {
useOnAppLifecycleStateChange((previous, current) async {
if (current == AppLifecycleState.resumed) {
if (currentPathIsSecurePath(appRouter)) appRouter.back();
await routeBackAfterSecurePage(appRouter);
}
if (
current == AppLifecycleState.inactive ||
Expand Down
1 change: 1 addition & 0 deletions pharme.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"drugclass",
"drugid",
"drugrecommendation",
"drugselection",
"duckdns",
"duloxetine",
"endoxifen",
Expand Down

0 comments on commit 2733d19

Please sign in to comment.