Skip to content

Commit

Permalink
feat(app): add expansion list for non-current drugs
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Nov 28, 2024
1 parent 08468d7 commit 57314c0
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 43 deletions.
22 changes: 15 additions & 7 deletions app/lib/common/widgets/drug_list/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DrugList extends StatelessWidget {
return errorIndicator(noDrugsMessage!);
}
List<Widget>? 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 {
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions app/lib/common/widgets/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
44 changes: 44 additions & 0 deletions app/lib/common/widgets/pretty_expansion_tile.dart
Original file line number Diff line number Diff line change
@@ -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<Widget> 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,
),
);
}
}
65 changes: 29 additions & 36 deletions app/lib/faq/pages/faq.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
],
),
);
}
Expand Down

0 comments on commit 57314c0

Please sign in to comment.