Skip to content

Commit

Permalink
fix(#636): update routing
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Dec 20, 2023
1 parent b4c95b5 commit 54288a8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
18 changes: 1 addition & 17 deletions app/lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,13 @@ class PharMeApp extends StatelessWidget {
_instance._appRouter.navigatorKey;

final _appRouter = AppRouter();
final _isLoggedIn = MetaData.instance.isLoggedIn ?? false;
final _onboardingDone = MetaData.instance.onboardingDone ?? false;
final _initialDrugSelectionDone =
MetaData.instance.initialDrugSelectionDone ?? false;

@override
Widget build(BuildContext context) {
return MaterialApp.router(
debugShowCheckedModeBanner: false,
routeInformationParser: _appRouter.defaultRouteParser(),
routerDelegate: _appRouter.delegate(
deepLinkBuilder: (deepLink) {
late String path;
path = !_isLoggedIn
? 'login'
: !_onboardingDone
? 'onboarding'
: !_initialDrugSelectionDone
? 'drugselection'
: 'main';
return DeepLink.path(path);
},
),
routerDelegate: _appRouter.delegate(deepLinkBuilder: getInitialRoute),
theme: PharMeTheme.light,
localizationsDelegates: [
AppLocalizations.delegate,
Expand Down
16 changes: 16 additions & 0 deletions app/lib/common/utilities/routing_utils.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import '../module.dart';

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

// Replace whole stack, see https://stackoverflow.com/a/73784156
Future<void> overwriteRoutes(
BuildContext context,
Expand Down
6 changes: 5 additions & 1 deletion app/lib/report/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import '../drug/module.dart';
export 'pages/gene.dart';
export 'pages/report.dart';

@RoutePage()
class ReportRootPage extends AutoRouter {}

final reportRoute = AutoRoute(
path: 'report',
page: ReportRoute.page,
page: ReportRootRoute.page,
children: [
AutoRoute(path: '', page: ReportRoute.page),
AutoRoute(page: GeneRoute.page),
drugRoute(),
],
Expand Down
10 changes: 8 additions & 2 deletions app/lib/search/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ import '../drug/module.dart';
// For generated routes
export 'pages/search.dart';

@RoutePage()
class SearchRootPage extends AutoRouter {}

final searchRoute = AutoRoute(
path: 'search',
page: SearchRoute.page,
children: [ drugRoute() ],
page: SearchRootRoute.page,
children: [
AutoRoute(path: '', page: SearchRoute.page),
drugRoute()
],
);

0 comments on commit 54288a8

Please sign in to comment.