diff --git a/app/lib/common/pages/privacy/privacy.dart b/app/lib/common/pages/privacy/privacy.dart new file mode 100644 index 00000000..05e8a7b1 --- /dev/null +++ b/app/lib/common/pages/privacy/privacy.dart @@ -0,0 +1,17 @@ +import '../../module.dart'; + +const privacyRoutes = CustomRoute( + path: 'privacy', + name: 'PrivacyRouter', + page: PrivacyPage, + transitionsBuilder: TransitionsBuilders.zoomIn, +); + +class PrivacyPage extends StatelessWidget { + const PrivacyPage({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return PharMeLogoPage(); + } +} \ No newline at end of file diff --git a/app/lib/common/routing/router.dart b/app/lib/common/routing/router.dart index 2545fa7f..c92567d7 100644 --- a/app/lib/common/routing/router.dart +++ b/app/lib/common/routing/router.dart @@ -7,6 +7,7 @@ import '../../report/module.dart'; import '../../search/module.dart'; import '../../settings/module.dart'; import '../pages/main/main.dart'; +import '../pages/privacy/privacy.dart'; part 'router.gr.dart'; @@ -16,6 +17,7 @@ part 'router.gr.dart'; drugSelectionRoutes, loginRoutes, onboardingRoutes, + privacyRoutes, AutoRoute( path: 'main', page: MainPage, diff --git a/app/lib/common/widgets/app.dart b/app/lib/common/widgets/app.dart index 9ba3bfd2..f7d81cc8 100644 --- a/app/lib/common/widgets/app.dart +++ b/app/lib/common/widgets/app.dart @@ -20,26 +20,29 @@ class PharMeApp extends StatelessWidget { @override Widget build(BuildContext context) { - return MaterialApp.router( - debugShowCheckedModeBanner: false, - routeInformationParser: _appRouter.defaultRouteParser(), - routerDelegate: _appRouter.delegate( - initialDeepLink: !_isLoggedIn - ? 'login' - : !_onboardingDone - ? 'onboarding' - : !_initialDrugSelectionDone - ? 'drugselection' - : 'main', + return LifecycleObserver( + appRouter: _appRouter, + child: MaterialApp.router( + debugShowCheckedModeBanner: false, + routeInformationParser: _appRouter.defaultRouteParser(), + routerDelegate: _appRouter.delegate( + initialDeepLink: !_isLoggedIn + ? 'login' + : !_onboardingDone + ? 'onboarding' + : !_initialDrugSelectionDone + ? 'drugselection' + : 'main', + ), + theme: PharMeTheme.light, + localizationsDelegates: [ + AppLocalizations.delegate, + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: [Locale('en', '')], ), - theme: PharMeTheme.light, - localizationsDelegates: [ - AppLocalizations.delegate, - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - GlobalCupertinoLocalizations.delegate, - ], - supportedLocales: [Locale('en', '')], ); } } diff --git a/app/lib/common/widgets/lifecycle_observer.dart b/app/lib/common/widgets/lifecycle_observer.dart new file mode 100644 index 00000000..4516b3ab --- /dev/null +++ b/app/lib/common/widgets/lifecycle_observer.dart @@ -0,0 +1,28 @@ +import '../module.dart'; + +class LifecycleObserver extends HookWidget { + const LifecycleObserver({ + Key? key, + required this.appRouter, + required this.child, + }) : super(key: key); + + final AppRouter appRouter; + final Widget child; + + @override + Widget build(BuildContext context) { + useOnAppLifecycleStateChange((previous, current) async { + if (current == AppLifecycleState.resumed) { + appRouter.navigateBack(); + } + if ( + current == AppLifecycleState.inactive || + current == AppLifecycleState.paused + ) { + await appRouter.push(PrivacyRouter()); + } + }); + return child; + } +} \ No newline at end of file diff --git a/app/lib/common/widgets/module.dart b/app/lib/common/widgets/module.dart index 70359f7f..a2cc429e 100644 --- a/app/lib/common/widgets/module.dart +++ b/app/lib/common/widgets/module.dart @@ -4,7 +4,9 @@ export 'drug_list/builder.dart'; export 'drug_list/cubit.dart'; export 'headings.dart'; export 'indicators.dart'; +export 'lifecycle_observer.dart'; export 'page_scaffold.dart'; +export 'pharme_logo_page.dart'; export 'radiant_gradient_mask.dart'; export 'rounded_card.dart'; export 'scroll_list.dart'; diff --git a/app/lib/common/widgets/pharme_logo_page.dart b/app/lib/common/widgets/pharme_logo_page.dart new file mode 100644 index 00000000..fc46a728 --- /dev/null +++ b/app/lib/common/widgets/pharme_logo_page.dart @@ -0,0 +1,33 @@ +import '../module.dart'; + +class PharMeLogoPage extends StatelessWidget { + const PharMeLogoPage({ + Key? key, + this.child, + }) : super(key: key); + + final Widget? child; + + @override + Widget build(BuildContext context) { + return unscrollablePageScaffold( + padding: PharMeTheme.largeSpace, + body: Column( + children: [ + Expanded( + child: Container( + alignment: Alignment.center, + child: SvgPicture.asset( + 'assets/images/logo.svg', + ), + ), + ), + Container( + alignment: Alignment.center, + child: child ?? SizedBox.shrink(), + ), + ], + ), + ); + } +} \ No newline at end of file diff --git a/app/lib/login/pages/login.dart b/app/lib/login/pages/login.dart index 90f5f5de..e39f8819 100644 --- a/app/lib/login/pages/login.dart +++ b/app/lib/login/pages/login.dart @@ -23,32 +23,14 @@ class LoginPage extends HookWidget { create: (context) => cubit ?? LoginPageCubit(activeDrugs), child: BlocBuilder( builder: (context, state) { - return unscrollablePageScaffold( - padding: PharMeTheme.largeSpace, - body: Stack( - children: [ - Positioned.fill( - child: Align( - alignment: Alignment.center, - child: SvgPicture.asset( - 'assets/images/logo.svg', - ), - ), - ), - Positioned( - child: Align( - alignment: Alignment.bottomCenter, - child: state.when( - initial: () => - _buildInitialScreen(context, dropdownValue), - loadingUserData: CircularProgressIndicator.new, - loadedUserData: () => _buildLoadedScreen(context), - error: (message) => - _buildErrorScreen(context, message), - ), - ), - ), - ], + return PharMeLogoPage( + child: state.when( + initial: () => + _buildInitialScreen(context, dropdownValue), + loadingUserData: CircularProgressIndicator.new, + loadedUserData: () => _buildLoadedScreen(context), + error: (message) => + _buildErrorScreen(context, message), ), ); },