UI libraries / Algolia for Flutter / Widgets

About this widget

Filter Toggle is a filtering view that displays any filter and lets users refine their search results by toggling the view on or off.

Examples

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class SearchToggleFilter extends StatelessWidget {
  const SearchToggleFilter(
      this.filterState, this.groupID, this.filter, this.label,
      {super.key});

  final FilterState filterState;
  final FilterGroupID groupID;
  final Filter filter;
  final String label;

  @override
  Widget build(BuildContext context) {
    return StreamBuilder(
        stream: filterState.filters,
        builder: (context, snapshot) {
          final filters = snapshot.hasData ? snapshot.data! : StatelessFilters();
          final filterGroups = filters.toFilterGroups().expand((group) => group);
          return FilterChip(
            label: Text(label),
            onSelected: (selected) => selected
                ? filterState.add(groupID, {filter})
                : filterState.remove(groupID, {filter}),
            selected: filterGroups.contains(filter),
          );
        });
  }
}
Did you find this page helpful?