From 1cb5e5f7fb493e9f5ddefa9abc957e563ba773f3 Mon Sep 17 00:00:00 2001 From: tamara-slosarek Date: Tue, 14 Jan 2025 13:03:19 +0100 Subject: [PATCH] feat(app): automatically expand further medications for further report gene card --- app/lib/common/widgets/drug_list/builder.dart | 5 ++++- app/lib/report/pages/gene.dart | 4 +++- app/lib/report/pages/report.dart | 22 ++++++++++++++----- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/app/lib/common/widgets/drug_list/builder.dart b/app/lib/common/widgets/drug_list/builder.dart index e55525c9..b90a3cb6 100644 --- a/app/lib/common/widgets/drug_list/builder.dart +++ b/app/lib/common/widgets/drug_list/builder.dart @@ -17,6 +17,7 @@ class DrugList extends HookWidget { this.noDrugsMessage, this.buildDrugItems = buildDrugCards, this.showDrugInteractionIndicator = false, + this.initiallyExpandFurtherMedications = false, this.searchForDrugClass = true, this.drugActivityChangeable = false, required this.buildContainer, @@ -27,6 +28,7 @@ class DrugList extends HookWidget { final String? noDrugsMessage; final DrugItemBuilder buildDrugItems; final bool showDrugInteractionIndicator; + final bool initiallyExpandFurtherMedications; final bool searchForDrugClass; // if drugActivityChangeable, active medications are not filtered and repeated // in the "All medications" list to make searching and toggling a medication's @@ -153,7 +155,8 @@ class DrugList extends HookWidget { initial: SizedBox.shrink, error: () => errorIndicator(context.l10n.err_generic), loaded: (allDrugs, filter) { - otherDrugsExpanded.value ??= drugActivityChangeable; + otherDrugsExpanded.value ??= + drugActivityChangeable || initiallyExpandFurtherMedications; return _buildDrugList(context, allDrugs, filter, otherDrugsExpanded); }, loading: loadingIndicator, diff --git a/app/lib/report/pages/gene.dart b/app/lib/report/pages/gene.dart index cf5fb57a..9db489ad 100644 --- a/app/lib/report/pages/gene.dart +++ b/app/lib/report/pages/gene.dart @@ -5,7 +5,7 @@ import '../../drug/widgets/module.dart'; @RoutePage() class GenePage extends HookWidget { - GenePage(this.genotypeResult) + GenePage(this.genotypeResult, {this.initiallyExpandFurtherMedications = false}) : cubit = DrugListCubit( initialFilter: FilterState.forGenotypeKey(genotypeResult.key.value), @@ -13,6 +13,7 @@ class GenePage extends HookWidget { final GenotypeResult genotypeResult; final DrugListCubit cubit; + final bool initiallyExpandFurtherMedications; @override Widget build(BuildContext context) { @@ -27,6 +28,7 @@ class GenePage extends HookWidget { state: state, activeDrugs: activeDrugs, noDrugsMessage: context.l10n.gene_page_no_relevant_drugs, + initiallyExpandFurtherMedications: initiallyExpandFurtherMedications, buildContainer: ({ children, indicator, diff --git a/app/lib/report/pages/report.dart b/app/lib/report/pages/report.dart index a8c23f74..c23e939f 100644 --- a/app/lib/report/pages/report.dart +++ b/app/lib/report/pages/report.dart @@ -71,8 +71,11 @@ class ReportPage extends HookWidget { List _buildGeneCards({ required SortOption currentSortOption, List? drugsToFilterBy, - required String keyPostfix, + required bool onlyCurrentMedications, }) { + final keyPostfix = onlyCurrentMedications + ? 'current-medications' + : 'all-medications'; final userGenotypes = _getRelevantGenotypes( drugsToFilterBy, ); @@ -114,6 +117,7 @@ class ReportPage extends HookWidget { warningLevelCounts[genotypeResult.key.value]!, key: Key('gene-card-${genotypeResult.key.value}-$keyPostfix'), useColors: false, + onlyCurrentMedications: onlyCurrentMedications, ) ).toList(); } @@ -239,7 +243,7 @@ class ReportPage extends HookWidget { final currentMedicationGenes = _buildGeneCards( currentSortOption: currentSortOption.value, drugsToFilterBy: activeDrugs.names, - keyPostfix: 'current-medications', + onlyCurrentMedications: true, ); final allMedicationGenesHeader = _listDescription( context, @@ -249,7 +253,7 @@ class ReportPage extends HookWidget { final allMedicationGenes = _buildGeneCards( currentSortOption: currentSortOption.value, drugsToFilterBy: null, - keyPostfix: 'all-medications', + onlyCurrentMedications: false, ); if (currentMedicationGenes.isEmpty) { return [ @@ -296,11 +300,13 @@ class GeneCard extends StatelessWidget { this.warningLevelCounts, { super.key, this.useColors = true, + this.onlyCurrentMedications = false, }); final GenotypeResult genotypeResult; final WarningLevelCounts warningLevelCounts; final bool useColors; + final bool onlyCurrentMedications; @visibleForTesting Color? get color => !useColors || _hasNoResult(genotypeResult) @@ -355,9 +361,13 @@ class GeneCard extends StatelessWidget { ) : null; return RoundedCard( - onTap: () => context.router.push( - GeneRoute(genotypeResult: genotypeResult) - ), + onTap: () async { + // ignore: use_build_context_synchronously + await context.router.push(GeneRoute( + genotypeResult: genotypeResult, + initiallyExpandFurtherMedications: !onlyCurrentMedications, + )); + }, radius: 16, color: color, child: Row(