Skip to content

Commit

Permalink
feat(#691): add active filter indicator to button
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Feb 23, 2024
1 parent fbd6b21 commit 883a831
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/lib/common/widgets/drug_search/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ class DrugSearch extends HookWidget {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
..._buildSearchBarItems(context, searchController),
if (showFilter) FilterButton(),
if (showFilter) FilterButton(
state,
activeDrugs,
useDrugClass: useDrugClass,
),
],
),
),
Expand Down
54 changes: 53 additions & 1 deletion app/lib/common/widgets/drug_search/filter_button.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,64 @@
import '../../module.dart';

class FilterButton extends StatelessWidget {
const FilterButton(
this.state,
this.activeDrugs,
{
required this.useDrugClass,
}
);

final DrugListState state;
final ActiveDrugs activeDrugs;
final bool useDrugClass;

@override
Widget build(BuildContext context) {
return IconButton(
icon: Icon(Icons.filter_list),
icon: Stack(
children: [
Icon(Icons.filter_list),
if (_showActiveIndicator()) _buildActiveIndicator(context),
],
),
color: PharMeTheme.iconColor,
onPressed: Scaffold.of(context).openDrawer,
);
}

bool _showActiveIndicator() {
final itemsAreFiltered = state.whenOrNull(
loaded: (allDrugs, filter) {
final totalNumberOfDrugs = allDrugs.length;
final currentNumberOfDrugs = filter.filter(
allDrugs,
activeDrugs,
useDrugClass: useDrugClass,
).length;
return totalNumberOfDrugs != currentNumberOfDrugs;
},
);
return itemsAreFiltered ?? false;
}

Widget _buildActiveIndicator(BuildContext context) {
const indicatorSize = PharMeTheme.smallToMediumSpace;
return Positioned(
right: 0,
bottom: 0,
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: PharMeTheme.sinaiPurple,
border: Border.all(
color: PharMeTheme.surfaceColor,
width: indicatorSize / 8,
),
),
width: indicatorSize,
height: indicatorSize,
),
);
}
}

0 comments on commit 883a831

Please sign in to comment.