From 9b4881797bc2702542d54d75b237536657b273e8 Mon Sep 17 00:00:00 2001 From: tamslo Date: Fri, 6 Dec 2024 12:19:11 +0100 Subject: [PATCH] feat(app): if inhibitor list only holds one item, just add as text --- .../common/widgets/gene_modulator_list.dart | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/app/lib/common/widgets/gene_modulator_list.dart b/app/lib/common/widgets/gene_modulator_list.dart index 51aff1ca..33d37072 100644 --- a/app/lib/common/widgets/gene_modulator_list.dart +++ b/app/lib/common/widgets/gene_modulator_list.dart @@ -1,6 +1,5 @@ import '../module.dart'; -// TODO(tamslo): if only one item, just print label and text afterwards class GeneModulatorList { const GeneModulatorList({ required this.geneName, @@ -57,8 +56,12 @@ class GeneModulatorList { final listString = StringBuffer(); for (final modulatorContentEntry in getContent(context).entries) { final entryString = StringBuffer(modulatorContentEntry.key); - for (final drugName in modulatorContentEntry.value) { - entryString.write('\n$linePrefix- $drugName'); + if (modulatorContentEntry.value.length == 1) { + entryString.write(' ${modulatorContentEntry.value.first}'); + } else { + for (final drugName in modulatorContentEntry.value) { + entryString.write('\n$linePrefix- $drugName'); + } } listString.write('\n$linePrefix$entryString'); } @@ -73,17 +76,29 @@ class GeneModulatorListWidget extends StatelessWidget { final GeneModulatorList listDefinition; - List _buildModulatorSublist(modulatorContentEntry) { + List _buildModulatorContent(modulatorContentEntry) { final descriptionText = modulatorContentEntry.key; final modulatorDrugNames = modulatorContentEntry.value; return [ SizedBox(height: PharMeTheme.smallSpace), - Text( - descriptionText, - style: TextStyle(fontStyle: FontStyle.italic), + if (modulatorDrugNames.length > 1) ...[ + Text( + descriptionText, + style: TextStyle(fontStyle: FontStyle.italic), + ), + SizedBox(height: PharMeTheme.smallSpace), + UnorderedList(modulatorDrugNames), + ], + if (modulatorDrugNames.length == 1) Text.rich(TextSpan( + children: [ + TextSpan( + text: descriptionText, + style: TextStyle(fontStyle: FontStyle.italic), + ), + TextSpan(text: ' '), + TextSpan(text: modulatorDrugNames.first), + ]) ), - SizedBox(height: PharMeTheme.smallSpace), - UnorderedList(modulatorDrugNames), ]; } @@ -93,7 +108,7 @@ class GeneModulatorListWidget extends StatelessWidget { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: - modulatorContent.entries.flatMap(_buildModulatorSublist).toList(), + modulatorContent.entries.flatMap(_buildModulatorContent).toList(), ); } } \ No newline at end of file