Skip to content

Commit eec57ad

Browse files
committed
feat(#664): adapt filter wording
1 parent 1bc95ea commit eec57ad

File tree

4 files changed

+90
-38
lines changed

4 files changed

+90
-38
lines changed

app/lib/common/widgets/context_menu.dart

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import '../module.dart';
55
class ContextMenu extends StatelessWidget {
66
const ContextMenu({
77
super.key,
8+
this.headerItem,
89
required this.items,
910
required this.child,
1011
});
1112

13+
final Widget? headerItem;
1214
final List<ContextMenuCheckmark> items;
1315
final Widget child;
1416

@@ -19,7 +21,9 @@ class ContextMenu extends StatelessWidget {
1921
showPopover(
2022
context: context,
2123
bodyBuilder: (context) => Padding(
22-
padding: EdgeInsets.symmetric(horizontal: 12),
24+
padding: EdgeInsets.symmetric(
25+
horizontal: PharMeTheme.smallToMediumSpace
26+
),
2327
child: Container(
2428
decoration: BoxDecoration(
2529
color: PharMeTheme.onSurfaceColor,
@@ -29,19 +33,7 @@ class ContextMenu extends StatelessWidget {
2933
child: Column(
3034
mainAxisSize: MainAxisSize.min,
3135
crossAxisAlignment: CrossAxisAlignment.start,
32-
children: items
33-
.mapIndexed(
34-
(index, item) => (index == items.count() - 1)
35-
? item
36-
: Container(
37-
decoration: BoxDecoration(
38-
border: Border(
39-
bottom: BorderSide(
40-
width: 0.5,
41-
color: PharMeTheme.borderColor),
42-
)),
43-
child: item))
44-
.toList(),
36+
children: _buildContent(context),
4537
),
4638
),
4739
),
@@ -57,6 +49,49 @@ class ContextMenu extends StatelessWidget {
5749
},
5850
child: child);
5951
}
52+
53+
Widget _itemContainer(
54+
Widget item,
55+
{
56+
bool showBorder = true,
57+
double padding = PharMeTheme.smallToMediumSpace,
58+
}
59+
) {
60+
return Container(
61+
decoration: showBorder ? BoxDecoration(
62+
border: Border(
63+
bottom: BorderSide(
64+
width: 0.5,
65+
color: PharMeTheme.borderColor
66+
),
67+
),
68+
) : null,
69+
child: Padding(
70+
padding: EdgeInsets.all(padding),
71+
child: item,
72+
)
73+
);
74+
}
75+
76+
List<Widget> _buildContent(BuildContext context) {
77+
final body = items.mapIndexed(
78+
(index, item) => (index == items.count() - 1)
79+
? _itemContainer(item, showBorder: false)
80+
: _itemContainer(item)
81+
).toList();
82+
return headerItem != null
83+
? [
84+
_itemContainer(
85+
Row(
86+
children: [headerItem!]
87+
),
88+
padding: PharMeTheme.mediumSpace,
89+
showBorder: false,
90+
),
91+
...body,
92+
]
93+
: body;
94+
}
6095
}
6196

6297
class ContextMenuCheckmark extends StatelessWidget {
@@ -81,18 +116,15 @@ class ContextMenuCheckmark extends StatelessWidget {
81116
setState(state);
82117
});
83118
},
84-
child: Padding(
85-
padding: EdgeInsets.all(12),
86-
child: Row(
87-
children: [
88-
if (state)
89-
Icon(Icons.check_rounded, size: 16)
90-
else
91-
SizedBox(width: 16, height: 16),
92-
SizedBox(width: 8),
93-
Expanded(child: Text(label)),
94-
],
95-
),
119+
child: Row(
120+
children: [
121+
if (state)
122+
Icon(Icons.check_box, size: PharMeTheme.mediumSpace)
123+
else
124+
Icon(Icons.check_box_outline_blank, size: PharMeTheme.mediumSpace),
125+
SizedBox(width: PharMeTheme.smallSpace),
126+
Expanded(child: Text(label)),
127+
],
96128
),
97129
),
98130
);

app/lib/common/widgets/drug_list/cubit.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,16 @@ class FilterState {
129129
[];
130130
final warningLevel =
131131
userGuideline?.annotations.warningLevel ?? WarningLevel.none;
132+
var warningLevelMatches = showWarningLevel[warningLevel] ?? true;
133+
// WarningLevel.none is also shown in green in app; therefore, it should
134+
// also be filtered with green option
135+
if (warningLevel == WarningLevel.none) {
136+
warningLevelMatches = warningLevelMatches &&
137+
showWarningLevel[WarningLevel.green]!;
138+
}
132139
final isDrugAccepted = drug.matches(query: query) &&
133140
(drug.isActive() || showInactive) &&
134-
(showWarningLevel[warningLevel] ?? true) &&
141+
warningLevelMatches &&
135142
(gene.isBlank || (guidelineGenes.contains(gene)));
136143
return isDrugAccepted;
137144
}

app/lib/common/widgets/drug_search.dart

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,31 @@ class DrugSearch extends HookWidget {
9494
return ContextMenu(
9595
items: [
9696
ContextMenuCheckmark(
97-
label: context.l10n.search_page_filter_inactive,
98-
setState: (state) => cubit.search(showInactive: state),
99-
initialState: filter?.showInactive ?? false),
100-
...WarningLevel.values.map((level) => ContextMenuCheckmark(
97+
label: context.l10n.search_page_filter_only_active,
98+
// Invert state as filter has opposite meaning ('only show active' vs.
99+
// 'show inactive')
100+
setState: (state) => cubit.search(showInactive: !state),
101+
initialState: filter != null && !filter.showInactive),
102+
...WarningLevel.values.filter((level) => level != WarningLevel.none)
103+
.map((level) => ContextMenuCheckmark(
101104
label: {
102105
WarningLevel.green: context.l10n.search_page_filter_green,
103106
WarningLevel.yellow: context.l10n.search_page_filter_yellow,
104107
WarningLevel.red: context.l10n.search_page_filter_red,
105-
WarningLevel.none: context.l10n.search_page_filter_gray,
106108
}[level]!,
107109
setState: (state) => cubit.search(showWarningLevel: {level: state}),
108-
initialState: filter?.showWarningLevel[level] ?? false))
110+
initialState: filter?.showWarningLevel[level] ?? false
111+
)
112+
),
113+
ContextMenuCheckmark(
114+
label: context.l10n.search_page_filter_only_with_guidelines,
115+
// Invert state as filter has opposite meaning ('show only with
116+
// guidelines' vs. 'show with unknown warning level')
117+
setState: (state) => cubit.search(
118+
showWarningLevel: {WarningLevel.none: !state}
119+
),
120+
initialState: filter != null &&
121+
!filter.showWarningLevel[WarningLevel.none]!,)
109122
],
110123
child: Padding(
111124
padding: EdgeInsets.all(8), child: Icon(Icons.filter_list_rounded)),

app/lib/l10n/app_en.arb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
"general_not_tested": "Not tested",
3131

3232
"search_page_tooltip_search": "Search for drugs by their name, brand name or class.",
33-
"search_page_filter_inactive": "Show currently not taken drugs",
34-
"search_page_filter_green": "Show green warning level",
35-
"search_page_filter_yellow": "Show yellow warning level",
36-
"search_page_filter_red": "Show red warning level",
37-
"search_page_filter_gray": "Show drugs without guidelines",
33+
"search_page_filter_only_active": "Only active drugs",
34+
"search_page_filter_green": "Green warning level",
35+
"search_page_filter_yellow": "Yellow warning level",
36+
"search_page_filter_red": "Red warning level",
37+
"search_page_filter_only_with_guidelines": "Only drugs with guidelines",
3838
"search_page_indicator_explanation": "Taking drugs with an {indicatorName} ({indicator}) can influence your results for other drugs",
3939
"@search_page_indicator_explanation": {
4040
"description": "Explanation of drug-drug interaction indicators",

0 commit comments

Comments
 (0)