FilterState holds one or several filters, organized in groups. filters streams filters changes of added or removed filters, which will be applied to searches performed by the connected Searcher.
Create
The following is an example of creating and setting up a FilterState with different filters (facets, tags and numerical):
const authors = FilterGroupID('author', FilterOperator.or);
const genres = FilterGroupID('genres');
const numbers = FilterGroupID('numbers');
final filterState = FilterState()
..add(authors, [Filter.facet('author', 'Shakespeare')])
..add(genres, [Filter.tag('drama')])
..add(numbers, [Filter.range('rating', lowerBound: 3, upperBound: 5)])
..add(numbers, [Filter.comparison('price', NumericOperator.less, 50)]);
The code snippet above corresponds to the following SQL-like expression:
(author:Shakespeare) AND (_tags:drama) AND (rating:3 TO 5 AND price < 50)
Update
FilterState can be updated using methods such as add, set and remove, each modification triggers a filters submission.
Running multiple modifications (atomically), and trigger a single filters submission can be done using modify method:
filterState.modify((filters) async =>
filters
.add(authors, [Filter.facet('author', 'J. K. Rowling')])
.remove(authors, [Filter.facet('author', 'Shakespeare')]));
Delete
Remove all or some filter groups using clear and clearExcept
filterState.clear(); // removes all filter groups
filterState.clear(authors); // clears filter group 'authors'
filterState.clearExcept([authors]); // clears all filter groups except 'authors'
- Implemented types
Constructors
- FilterState()
-
FilterState's factory.
factory
Properties
-
filters
→ Stream<
Filters> -
Filters groups stream (facet, tag, numeric and hierarchical).
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isDisposed → bool
-
Whether this Disposable has already released its resources.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
add(
FilterGroupID groupID, Iterable< Filter> filters) → void -
Adds
filters
to the providedgroupID
. -
addHierarchical(
String attribute, HierarchicalFilter hierarchicalFilter) → void -
Adds
hierarchicalFilter
to givenattribute
. -
clear(
[Iterable< FilterGroupID> ? groupIDs]) → void -
Clears
groupIDs
. If none provided, all filters will be cleared. -
clearExcept(
Iterable< FilterGroupID> groupIDs) → void -
Clears all except
groupIDs
. -
contains(
FilterGroupID groupID, Filter filter) → bool -
Checks if
filter
exists ingroupID
. -
dispose(
) → void -
Releases this Disposable resources.
inherited
-
modify(
AsyncFiltersBuilder builder) → Future< void> -
Asynchronous updates filters by applying
builder
to current filters value. Useful to apply multiple consecutive update operations without firing multiple filters events. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
remove(
FilterGroupID groupID, Iterable< Filter> filters) → void -
Removes
filters
fromgroupID
. -
removeHierarchical(
String attribute) → void -
Removes HierarchicalFilter of given
attribute
. -
set(
Map< FilterGroupID, Set< map) → voidFilter> > -
Overrides filters with the provided
map
. -
snapshot(
) → Filters - Get current filters value.
-
toggle(
FilterGroupID groupID, Filter filter) → void -
Toggles
filter
in givengroupID
. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited