diff --git a/app/lib/common/widgets/drug_list/builder.dart b/app/lib/common/widgets/drug_list/builder.dart index 82c4e6be..910b4b5f 100644 --- a/app/lib/common/widgets/drug_list/builder.dart +++ b/app/lib/common/widgets/drug_list/builder.dart @@ -48,7 +48,7 @@ class DrugList extends StatelessWidget { return errorIndicator(noDrugsMessage!); } List? activeDrugsList; - // Do not show repeated active drugs when searching + // Do not show repeated active drugs when searching in medication selection if (drugActivityChangeable && filteredDrugs.length != drugs.length) { activeDrugsList = null; } else { @@ -84,12 +84,20 @@ class DrugList extends StatelessWidget { ), ...activeDrugsList, ], - if (activeDrugsList != null && allDrugsList.isNotEmpty) SubheaderDivider( - text: otherDrugsHeader, - key: Key('header-other'), - useLine: false, - ), - ...allDrugsList, + if (activeDrugsList != null && allDrugsList.isNotEmpty) + PrettyExpansionTile( + title: SubheaderDivider( + text: otherDrugsHeader, + key: Key('header-other'), + useLine: false, + ), + initiallyExpanded: drugActivityChangeable || filter.query.isNotBlank, + visualDensity: VisualDensity.compact, + titlePadding: EdgeInsets.zero, + childrenPadding: EdgeInsets.zero, + children: allDrugsList, + ), + if (activeDrugsList == null) ...allDrugsList, ]; return (buildContainer != null) ? buildContainer!(drugLists) diff --git a/app/lib/common/widgets/module.dart b/app/lib/common/widgets/module.dart index 29e72f91..e7dc6978 100644 --- a/app/lib/common/widgets/module.dart +++ b/app/lib/common/widgets/module.dart @@ -22,6 +22,7 @@ export 'page_description.dart'; export 'page_indicator_explanation.dart'; export 'page_scaffold.dart'; export 'pharme_logo_page.dart'; +export 'pretty_expansion_tile.dart'; export 'radiant_gradient_mask.dart'; export 'rounded_card.dart'; export 'scroll_list.dart'; diff --git a/app/lib/common/widgets/pretty_expansion_tile.dart b/app/lib/common/widgets/pretty_expansion_tile.dart new file mode 100644 index 00000000..22f11479 --- /dev/null +++ b/app/lib/common/widgets/pretty_expansion_tile.dart @@ -0,0 +1,44 @@ +import '../module.dart'; + +class PrettyExpansionTile extends StatelessWidget { + const PrettyExpansionTile({ + super.key, + required this.title, + required this.children, + this.onExpansionChanged, + this.visualDensity, + this.titlePadding, + this.childrenPadding, + this.initiallyExpanded = false, + }); + + final Widget title; + // ignore: avoid_positional_boolean_parameters + final void Function(bool)? onExpansionChanged; + final List children; + final VisualDensity? visualDensity; + final EdgeInsets? titlePadding; + final EdgeInsets? childrenPadding; + final bool initiallyExpanded; + + @override + Widget build(BuildContext context) { + return Theme( + data: Theme.of(context).copyWith( + dividerColor: Colors.transparent, + ), + child: ExpansionTile( + key: GlobalKey(), // force to rebuild + initiallyExpanded: initiallyExpanded, + title: title, + iconColor: PharMeTheme.iconColor, + collapsedIconColor: PharMeTheme.iconColor, + onExpansionChanged: onExpansionChanged, + visualDensity: visualDensity, + tilePadding: titlePadding, + childrenPadding: childrenPadding, + children: children, + ), + ); + } +} \ No newline at end of file diff --git a/app/lib/faq/pages/faq.dart b/app/lib/faq/pages/faq.dart index 553fe8cc..b433c2d4 100644 --- a/app/lib/faq/pages/faq.dart +++ b/app/lib/faq/pages/faq.dart @@ -93,44 +93,37 @@ class FaqPage extends HookWidget { final expanded = expandedCards.value.containsKey(question.question); return _buildQuestionCard( key: key, - child: Theme( - data: Theme.of(context).copyWith( - dividerColor: Colors.transparent, + child: PrettyExpansionTile( + initiallyExpanded: expanded, + title: Text( + question.question, + style: expanded + ? PharMeTheme.textTheme.bodyLarge!.copyWith( + fontWeight: FontWeight.bold, + ) + : null, ), - child: ExpansionTile( - initiallyExpanded: expanded, - title: Text( - question.question, - style: expanded - ? PharMeTheme.textTheme.bodyLarge!.copyWith( - fontWeight: FontWeight.bold, - ) - : null, - ), - iconColor: PharMeTheme.iconColor, - collapsedIconColor: PharMeTheme.iconColor, - onExpansionChanged: (value) { - if (value) { - expandQuestion.value = question.question; - } else { - expandedCards.value = expandedCards.value.filterKeys( - (questionTitle) => questionTitle != question.question - ); - } - }, - children: [ - ListTile( - contentPadding: EdgeInsets.only( - left: PharMeTheme.mediumSpace, - right: PharMeTheme.mediumSpace, - bottom: PharMeTheme.smallSpace, - ), - title: question is FaqTextAnswerQuestion - ? Text(question.answer) - : question.answer, + onExpansionChanged: (value) { + if (value) { + expandQuestion.value = question.question; + } else { + expandedCards.value = expandedCards.value.filterKeys( + (questionTitle) => questionTitle != question.question + ); + } + }, + children: [ + ListTile( + contentPadding: EdgeInsets.only( + left: PharMeTheme.mediumSpace, + right: PharMeTheme.mediumSpace, + bottom: PharMeTheme.smallSpace, ), - ], - ), + title: question is FaqTextAnswerQuestion + ? Text(question.answer) + : question.answer, + ), + ], ), ); }