From 5d29503af45a0b56d1cdf11f2cae94539437a3a4 Mon Sep 17 00:00:00 2001 From: Tamara Slosarek Date: Wed, 18 Sep 2024 15:42:31 +0200 Subject: [PATCH] feat(app): change search behavior in drug list if activity is changeable --- app/lib/common/widgets/drug_list/builder.dart | 22 +++++++++---------- .../common/widgets/drug_search/builder.dart | 6 ++--- .../drug_selection/pages/drug_selection.dart | 2 +- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/app/lib/common/widgets/drug_list/builder.dart b/app/lib/common/widgets/drug_list/builder.dart index e06b1651..bca9af88 100644 --- a/app/lib/common/widgets/drug_list/builder.dart +++ b/app/lib/common/widgets/drug_list/builder.dart @@ -18,7 +18,7 @@ class DrugList extends StatelessWidget { this.buildDrugItems = buildDrugCards, this.showDrugInteractionIndicator = false, this.searchForDrugClass = true, - this.repeatMedicationsWhenNotFiltered = false, + this.drugActivityChangeable = false, this.buildContainer, }); @@ -28,7 +28,10 @@ class DrugList extends StatelessWidget { final DrugItemBuilder buildDrugItems; final bool showDrugInteractionIndicator; final bool searchForDrugClass; - final bool repeatMedicationsWhenNotFiltered; + // if drugActivityChangeable, active medications are not filtered and repeated + // in the "All medications" list to make searching and toggling a medication's + // activity less confusing + final bool drugActivityChangeable; final Widget Function(List children)? buildContainer; Widget _buildDrugList( @@ -44,8 +47,9 @@ class DrugList extends StatelessWidget { if (filteredDrugs.isEmpty && noDrugsMessage != null) { return errorIndicator(noDrugsMessage!); } - final activeFilteredDrugs = - filteredDrugs.filter((drug) => drug.isActive).toList(); + final activeFilteredDrugs = drugActivityChangeable + ? drugs.filter((drug) => drug.isActive).toList() + : filteredDrugs.filter((drug) => drug.isActive).toList(); final activeDrugsList = activeFilteredDrugs.isNotEmpty ? buildDrugItems( context, @@ -54,16 +58,10 @@ class DrugList extends StatelessWidget { keyPrefix: 'active-', ) : null; - final repeatMedications = repeatMedicationsWhenNotFiltered && - !areDrugsFiltered( - state: state, - activeDrugs: activeDrugs, - searchForDrugClass: searchForDrugClass, - ); - final otherDrugs = repeatMedications + final otherDrugs = drugActivityChangeable ? filteredDrugs : filteredDrugs.filter((drug) => !drug.isActive).toList(); - final otherDrugsHeader = repeatMedications + final otherDrugsHeader = drugActivityChangeable ? context.l10n.drug_list_subheader_all_drugs : context.l10n.drug_list_subheader_other_drugs; final allDrugsList = buildDrugItems( diff --git a/app/lib/common/widgets/drug_search/builder.dart b/app/lib/common/widgets/drug_search/builder.dart index 0d50878d..4f0bbac8 100644 --- a/app/lib/common/widgets/drug_search/builder.dart +++ b/app/lib/common/widgets/drug_search/builder.dart @@ -15,13 +15,13 @@ class DrugSearch extends HookWidget { required this.state, required this.activeDrugs, this.keepPosition = false, - this.repeatMedications = false, + this.drugActivityChangeable = false, }); final bool showFilter; final bool searchForDrugClass; final bool keepPosition; - final bool repeatMedications; + final bool drugActivityChangeable; final DrugItemBuilder buildDrugItems; final bool showDrugInteractionIndicator; final DrugListCubit cubit; @@ -57,7 +57,7 @@ class DrugSearch extends HookWidget { searchForDrugClass: searchForDrugClass, buildContainer: (children) => scrollList(keepPosition: keepPosition, children), - repeatMedicationsWhenNotFiltered: repeatMedications, + drugActivityChangeable: drugActivityChangeable, ), _maybeBuildInteractionIndicator(context, state, activeDrugs) ?? SizedBox.shrink(), diff --git a/app/lib/drug_selection/pages/drug_selection.dart b/app/lib/drug_selection/pages/drug_selection.dart index 8a008e31..e6545134 100644 --- a/app/lib/drug_selection/pages/drug_selection.dart +++ b/app/lib/drug_selection/pages/drug_selection.dart @@ -116,7 +116,7 @@ class DrugSelectionPage extends HookWidget { )), showDrugInteractionIndicator: !concludesOnboarding, // to not confuse users when selecting a medication that then is removed from the list - repeatMedications: true, + drugActivityChangeable: true, ), ); }