-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#691): add active filter indicator to button
- Loading branch information
Showing
2 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
), | ||
); | ||
} | ||
} |