Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/677 privacy screen #690

Merged
merged 9 commits into from
Dec 27, 2023
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ Before you begin with setting up your local development environment, ensure that
you have the following list of tools installed:

- An editor, we **strongly recommend** [<img
alt="vscode-icon"
alt="vscode-logo"
src="https://user-images.githubusercontent.com/82543715/142914400-49d5815b-71a7-4198-9501-157fc3aa40a2.png"
width="16" height="16"> Visual Studio Code](https://code.visualstudio.com)
- [<img
alt="git-icon"
alt="git-logo"
src="https://user-images.githubusercontent.com/82543715/142914382-5be71efd-9e34-46c2-aad6-04255c430594.png"
width="16" height="16"> Git](https://git-scm.com/downloads)
- [<img
alt="docker-icon"
alt="docker-logo"
src="https://user-images.githubusercontent.com/58258541/143049489-668aea70-bb2c-420d-b3e8-e0edc42a4e92.png"
width="16" height="16"> Docker](https://docs.docker.com/get-docker/)
- [<img
alt="nodejs-icon"
alt="nodejs-logo"
src="https://user-images.githubusercontent.com/58258541/143050266-4a2030d1-c319-447d-812b-2ad8a4020d48.png"
width="16" height="16"> NodeJS](https://nodejs.org)
- [<img
alt="yarn-icon"
alt="yarn-logo"
src="https://user-images.githubusercontent.com/58258541/143050227-b374b1f7-e28e-4b90-b7f0-b9112521d3b1.png"
width="16" height="16"> Yarn](https://yarnpkg.com/)

Expand Down
2 changes: 1 addition & 1 deletion app/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if (localPropertiesFile.exists()) {

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
throw new Exception("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
Expand Down
27 changes: 15 additions & 12 deletions app/lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ class PharMeApp extends StatelessWidget {

@override
Widget build(BuildContext context) {
return MaterialApp.router(
debugShowCheckedModeBanner: false,
routeInformationParser: _appRouter.defaultRouteParser(),
routerDelegate: _appRouter.delegate(deepLinkBuilder: getInitialRoute),
theme: PharMeTheme.light,
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [Locale('en', '')],
return LifecycleObserver(
appRouter: _appRouter,
child: MaterialApp.router(
debugShowCheckedModeBanner: false,
routeInformationParser: _appRouter.defaultRouteParser(),
routerDelegate: _appRouter.delegate(deepLinkBuilder: getInitialRoute),
theme: PharMeTheme.light,
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [Locale('en', '')],
),
);
}
}
4 changes: 3 additions & 1 deletion app/lib/common/routing/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import '../../more/module.dart';
import '../../onboarding/module.dart';
import '../../report/module.dart';
import '../../search/module.dart';
import '../../secure/module.dart';
import '../module.dart';

part 'router.gr.dart';
Expand All @@ -19,7 +20,6 @@ class AppRouter extends _$AppRouter {
List<AutoRoute> get routes => [
drugSelectionRoute(),
loginRoute(),
onboardingRoute(),
mainRoute(
children: [
reportRoute(children: [ geneRoute(), drugRoute() ]),
Expand All @@ -30,5 +30,7 @@ class AppRouter extends _$AppRouter {
),
],
),
onboardingRoute(),
secureRoute(),
];
}
1 change: 1 addition & 0 deletions app/lib/common/services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Future<void> initServices() async {
await initMetaData();
await initUserData();
await initCachedDrugs();
WidgetsFlutterBinding.ensureInitialized();
}

Future<void> cleanupServices() async {
Expand Down
5 changes: 5 additions & 0 deletions app/lib/common/utilities/routing_utils.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '../../secure/module.dart';
import '../module.dart';

DeepLink getInitialRoute(_) {
Expand All @@ -16,6 +17,10 @@ DeepLink getInitialRoute(_) {
return DeepLink.path(path);
}

bool currentPathIsSecurePath(AppRouter appRouter) {
return appRouter.currentPath == secureRoutePath;
}

// Replace whole stack, see https://stackoverflow.com/a/73784156
Future<void> overwriteRoutes(
BuildContext context,
Expand Down
30 changes: 30 additions & 0 deletions app/lib/common/widgets/lifecycle_observer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import '../module.dart';

class LifecycleObserver extends HookWidget {
const LifecycleObserver({
super.key,
required this.appRouter,
required this.child,
});

final AppRouter appRouter;
final Widget child;

@override
Widget build(BuildContext context) {
useOnAppLifecycleStateChange((previous, current) async {
if (current == AppLifecycleState.resumed) {
if (currentPathIsSecurePath(appRouter)) appRouter.back();
}
if (
current == AppLifecycleState.inactive ||
current == AppLifecycleState.paused
) {
if (!currentPathIsSecurePath(appRouter)) {
await appRouter.push(SecureRoute());
}
}
});
return child;
}
}
2 changes: 2 additions & 0 deletions app/lib/common/widgets/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ export 'drug_list/cubit.dart';
export 'filter_menu.dart';
export 'headings.dart';
export 'indicators.dart';
export 'lifecycle_observer.dart';
export 'page_indicator_explanation.dart';
export 'page_scaffold.dart';
export 'pharme_logo_page.dart';
export 'radiant_gradient_mask.dart';
export 'rounded_card.dart';
export 'scroll_list.dart';
Expand Down
33 changes: 33 additions & 0 deletions app/lib/common/widgets/pharme_logo_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import '../module.dart';

class PharMeLogoPage extends StatelessWidget {
const PharMeLogoPage({
super.key,
this.child,
});

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(),
),
],
),
);
}
}
34 changes: 8 additions & 26 deletions app/lib/login/pages/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,14 @@ class LoginPage extends HookWidget {
create: (context) => cubit ?? LoginCubit(activeDrugs),
child: BlocBuilder<LoginCubit, LoginState>(
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),
),
);
},
Expand Down
2 changes: 1 addition & 1 deletion app/lib/more/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export 'pages/more.dart';
export 'pages/privacy.dart';
export 'pages/terms.dart';

@RoutePage()
@RoutePage()
class MoreRootPage extends AutoRouter {}

AutoRoute aboutRoute() => AutoRoute(path: 'about', page: AboutRoute.page);
Expand Down
2 changes: 1 addition & 1 deletion app/lib/report/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import '../common/module.dart';
export 'pages/gene.dart';
export 'pages/report.dart';

@RoutePage()
@RoutePage()
class ReportRootPage extends AutoRouter {}

AutoRoute geneRoute() => AutoRoute(page: GeneRoute.page);
Expand Down
2 changes: 1 addition & 1 deletion app/lib/search/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import '../common/module.dart';
// For generated routes
export 'pages/search.dart';

@RoutePage()
@RoutePage()
class SearchRootPage extends AutoRouter {}

AutoRoute searchRoute({ required List<AutoRoute> children }) => AutoRoute(
Expand Down
12 changes: 12 additions & 0 deletions app/lib/secure/module.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import '../common/module.dart';

// For generated routes
export 'pages/secure.dart';

const secureRoutePath = '/secure';

CustomRoute secureRoute() => CustomRoute(
path: secureRoutePath,
page: SecureRoute.page,
transitionsBuilder: TransitionsBuilders.fadeIn,
);
11 changes: 11 additions & 0 deletions app/lib/secure/pages/secure.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import '../../common/module.dart';

@RoutePage()
class SecurePage extends StatelessWidget {
const SecurePage({super.key});

@override
Widget build(BuildContext context) {
return PharMeLogoPage();
}
}
Loading