Skip to content

Commit

Permalink
fix(app): use switch for current medication selection (less buggy)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Aug 29, 2024
1 parent 8378f71 commit aaeab8c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 67 deletions.
106 changes: 43 additions & 63 deletions app/lib/drug/widgets/annotation_cards/drug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,48 @@ class DrugAnnotationCards extends StatelessWidget {
Widget build(BuildContext context) {
return Column(
children: [
RoundedCard(
innerPadding: EdgeInsets.symmetric(horizontal: PharMeTheme.mediumSpace),
child: SwitchListTile.adaptive(
value: isActive,
activeColor: PharMeTheme.primaryColor,
title: Text(context.l10n.drugs_page_text_active),
contentPadding: EdgeInsets.zero,
onChanged: disabled ? null : (newValue) {
if (isInhibitor(drug.name)) {
showAdaptiveDialog(
context: context,
builder: (context) => DialogWrapper(
title: context.l10n.drugs_page_active_warn_header,
content: DialogContentText(
context.l10n.drugs_page_active_warn,
),
actions: [
DialogAction(
onPressed: () => Navigator.pop(
context,
'Cancel',
),
text: context.l10n.action_cancel,
),
DialogAction(
onPressed: () {
Navigator.pop(context, 'OK');
setActivity(value: newValue);
},
text: context.l10n.action_continue,
isDestructive: true,
),
],
),
);
} else {
setActivity(value: newValue);
}
},
),
),
SizedBox(height: PharMeTheme.smallSpace),
SubHeader(context.l10n.drugs_page_header_drug),
SizedBox(height: PharMeTheme.smallSpace),
RoundedCard(
Expand All @@ -40,7 +82,7 @@ class DrugAnnotationCards extends StatelessWidget {
),
]),
if (isInhibitor(drug.name)) ...[
SizedBox(height: 8),
SizedBox(height: PharMeTheme.smallSpace),
buildTable(
[TableRowDefinition(
drugInteractionIndicator,
Expand All @@ -56,68 +98,6 @@ class DrugAnnotationCards extends StatelessWidget {
),
),
),
SizedBox(height: PharMeTheme.mediumSpace),
SubHeader(context.l10n.drugs_page_header_active),
SizedBox(height: PharMeTheme.smallSpace),
RoundedCard(
innerPadding: EdgeInsets.all(PharMeTheme.smallSpace),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: PharMeTheme.smallSpace),
child: DropdownButton<bool>(
key: Key('drug-status-selection-${drug.name}'),
value: isActive,
isExpanded: true,
icon: const Icon(Icons.expand_more),
onChanged: disabled ? null : (newValue) => {
if (isInhibitor(drug.name)) {
showAdaptiveDialog(
context: context,
builder: (context) => DialogWrapper(
title: context.l10n.drugs_page_active_warn_header,
content: DialogContentText(
context.l10n.drugs_page_active_warn,
),
actions: [
DialogAction(
onPressed: () => Navigator.pop(context, 'Cancel'),
text: context.l10n.action_cancel,
),
DialogAction(
onPressed: () {
Navigator.pop(context, 'OK');
setActivity(value: newValue);
},
text: context.l10n.action_continue,
isDestructive: true,
),
],
),
)
} else {
setActivity(value: newValue)
}
},
items: [
DropdownMenuItem<bool>(
key: Key('drug-status-selection-${drug.name}-active'),
value: true,
child: _buildStatusMenuItem(
context.l10n.drugs_page_active,
Icons.check_circle_outline,
),
),
DropdownMenuItem<bool>(
key: Key('drug-status-selection-${drug.name}-inactive'),
value: false,
child: _buildStatusMenuItem(
context.l10n.drugs_page_inactive,
Icons.cancel_outlined,
),
),
],
),
),
),
],
);
}
Expand Down
6 changes: 2 additions & 4 deletions app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,10 @@
"example": "bupropion"
}
}
},
},
"drugs_page_header_drugclass": "Medication class",
"drugs_page_header_drug": "Medication information",
"drugs_page_header_active": "Usage status",
"drugs_page_active": "I am currently taking this medication",
"drugs_page_inactive": "I am not taking this medication",
"drugs_page_text_active": "Current medication",
"drugs_page_active_warn_header": "Are you sure you want to change the medication usage status?",
"drugs_page_active_warn": "This can interact with your results for other medications.",
"drugs_page_header_guideline": "DNA-based clinical guideline",
Expand Down

0 comments on commit aaeab8c

Please sign in to comment.