-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
161 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import '../module.dart'; | ||
|
||
class FullWidthButton extends StatelessWidget { | ||
const FullWidthButton( | ||
this.text, | ||
this.action, { | ||
Key? key, | ||
}) : super(key: key); | ||
|
||
final String text; | ||
final void Function() action; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SizedBox( | ||
width: double.infinity, | ||
child: ElevatedButton( | ||
onPressed: action, | ||
style: ButtonStyle( | ||
shape: MaterialStateProperty.all<RoundedRectangleBorder>( | ||
RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(32), | ||
), | ||
), | ||
), | ||
child: Text(text), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import '../common/module.dart'; | ||
import 'pages/drugselection.dart'; | ||
|
||
// We need to expose all pages for AutoRouter | ||
export 'pages/cubit.dart'; | ||
export 'pages/drugselection.dart'; | ||
|
||
const drugSelectionRoutes = AutoRoute( | ||
path: 'drugselection', | ||
name: 'DrugSelectionRouter', | ||
page: DrugSelectionPage, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
import '../../../common/module.dart'; | ||
import '../../common/pages/drug/cubit.dart'; | ||
|
||
part 'cubit.freezed.dart'; | ||
|
||
class DrugSelectionPageCubit extends Cubit<DrugSelectionPageState> { | ||
DrugSelectionPageCubit() : super(DrugSelectionPageState.stable()); | ||
|
||
// ignore: avoid_positional_boolean_parameters | ||
Future<void> updateDrugActivity(Drug drug, bool? value) async { | ||
if (value == null) return; | ||
emit(DrugSelectionPageState.updating()); | ||
await setDrugActivity(drug, value); | ||
emit(DrugSelectionPageState.stable()); | ||
} | ||
} | ||
|
||
@freezed | ||
class DrugSelectionPageState with _$DrugSelectionPageState { | ||
const factory DrugSelectionPageState.stable() = _StableState; | ||
const factory DrugSelectionPageState.updating() = _UpdatingState; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import '../../common/models/drug/cached_drugs.dart'; | ||
import '../../common/module.dart' hide MetaData; | ||
import '../../common/widgets/full_width_button.dart'; | ||
import 'cubit.dart'; | ||
|
||
class DrugSelectionPage extends HookWidget { | ||
const DrugSelectionPage({ | ||
Key? key, | ||
@visibleForTesting this.cubit, | ||
}) : super(key: key); | ||
|
||
final DrugSelectionPageCubit? cubit; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return BlocProvider( | ||
create: (context) => cubit ?? DrugSelectionPageCubit(), | ||
child: BlocBuilder<DrugSelectionPageCubit, DrugSelectionPageState>( | ||
builder: (context, state) { | ||
return Scaffold( | ||
body: SafeArea( | ||
child: Padding( | ||
padding: const EdgeInsets.all(16), | ||
child: Column( | ||
children: [ | ||
Padding( | ||
padding: const EdgeInsets.all(8), | ||
child: Column( | ||
children: [ | ||
Text( | ||
context.l10n.drug_selection_header, | ||
style: PharMeTheme.textTheme.titleLarge), | ||
SizedBox(height: PharMeTheme.mediumSpace), | ||
Text(context.l10n.drug_selection_description), | ||
SizedBox(height: PharMeTheme.mediumSpace), | ||
Text(context.l10n.drug_selection_later), | ||
SizedBox(height: PharMeTheme.mediumSpace), | ||
]), | ||
), | ||
state.when( | ||
stable: () => | ||
Column( | ||
children: [ | ||
ListView(shrinkWrap: true, | ||
children: CachedDrugs.instance.drugs!.map( | ||
(drug) => CheckboxListTile( | ||
value: UserData.instance.activeDrugNames! | ||
.contains(drug.name), | ||
onChanged: (value) { | ||
context | ||
.read<DrugSelectionPageCubit>() | ||
.updateDrugActivity(drug, value); | ||
}, | ||
title: Text(drug.name.capitalize()), | ||
subtitle: Text( | ||
'(${drug.annotations.brandNames.join(", ")})' | ||
), | ||
)).toList(), | ||
), | ||
SizedBox(height: PharMeTheme.mediumSpace), | ||
FullWidthButton( | ||
context.l10n.general_continue, | ||
() { context.router.replace(MainRoute()); } | ||
), | ||
] | ||
), | ||
updating: CircularProgressIndicator.new, | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters