-
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.
Merge pull request #616 from hpi-dhc/issue/480-active-drugs-onboarding
Issue/480 active drugs onboarding
- Loading branch information
Showing
11 changed files
with
202 additions
and
37 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
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,32 @@ | ||
import '../module.dart'; | ||
|
||
class FullWidthButton extends StatelessWidget { | ||
const FullWidthButton( | ||
this.text, | ||
this.action, { | ||
Key? key, | ||
this.enabled = true, | ||
}) : super(key: key); | ||
|
||
final bool enabled; | ||
final String text; | ||
final void Function() action; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SizedBox( | ||
width: double.infinity, | ||
child: ElevatedButton( | ||
onPressed: enabled ? action : null, | ||
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,95 @@ | ||
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: ListView( | ||
children: [ | ||
_buildHeader(context), | ||
..._buildDrugList(context, state), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
) | ||
); | ||
} | ||
|
||
Widget _buildHeader(BuildContext context) { | ||
return Padding( | ||
padding: const EdgeInsets.all(8), | ||
child: Column( | ||
children: [ | ||
Text( | ||
context.l10n.drug_selection_header, | ||
style: PharMeTheme.textTheme.headlineLarge), | ||
SizedBox(height: PharMeTheme.mediumSpace), | ||
Text( | ||
context.l10n.drug_selection_description, | ||
style: PharMeTheme.textTheme.bodyLarge), | ||
SizedBox(height: PharMeTheme.mediumSpace), | ||
Text( | ||
context.l10n.drug_selection_later, | ||
style: PharMeTheme.textTheme.bodyLarge), | ||
SizedBox(height: PharMeTheme.mediumSpace), | ||
] | ||
), | ||
); | ||
} | ||
|
||
List<Widget> _buildDrugList( | ||
BuildContext context, | ||
DrugSelectionPageState state | ||
) { | ||
var enabled = true; | ||
state.when( | ||
stable: () => enabled = true, | ||
updating: () => enabled = false | ||
); | ||
return [ | ||
// ...[...CachedDrugs.instance.drugs!, ...CachedDrugs.instance.drugs!, ...CachedDrugs.instance.drugs!].map( | ||
...CachedDrugs.instance.drugs!.map( | ||
(drug) => CheckboxListTile( | ||
enabled: enabled, | ||
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()); }, | ||
enabled: enabled, | ||
), | ||
]; | ||
} | ||
} |
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
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