Filter class
A Filter represents a restriction on one or more field values and can be
used to refine the results of a Query (see Query.where).
Filters can be combined with Filter.or and Filter.and to build disjunctions (OR queries) and conjunctions.
Filter.new takes the same arguments as Query.where (Filter('age', isGreaterThan: 18)).
A String field is split on dots ('address.city' is a nested field); a FieldPath names a
field whose name contains a dot. The value is checked when the filter is added to a query,
which throws an ArgumentError for a value or a combination of filters that Firestore does
not accept (for example an empty list for whereIn, or two whereNotIn filters).
// Cities in California with more than a million people, or any capital.
final QuerySnapshot<Map<String, Object?>> snapshot = await firestore
.collection('cities')
.where(
Filter.or([
Filter.and([
Filter('state', isEqualTo: 'CA'),
Filter('population', isGreaterThan: 1000000),
]),
Filter('capital', isEqualTo: true),
]),
)
.get();
Prefer Filter to the loose arguments of Query.where when you build conditions in code: the combinators
take any Iterable of filters and the type of a filter is checked by the compiler.
Subclassing Note: Firestore classes are not meant to be subclassed.
Constructors
-
Filter(Object field, {Object? isEqualTo, Object? isNotEqualTo, Object? isLessThan, Object? isLessThanOrEqualTo, Object? isGreaterThan, Object? isGreaterThanOrEqualTo, Object? arrayContains, Iterable<
Object?> ? arrayContainsAny, Iterable<Object?> ? whereIn, Iterable<Object?> ? whereNotIn, bool? isNull}) -
A filter on
field, a String (dots separate nested fields) or a FieldPath, with exactly one of the named arguments: the same arguments asQuery.where.factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
and(
Iterable< Filter> filters) → Filter - Creates a new filter that is a conjunction of the given filters. A conjunction filter includes a document if it satisfies all of the given filters. An empty list adds no filter to the query.
-
or(
Iterable< Filter> filters) → Filter - Creates a new filter that is a disjunction of the given filters. A disjunction filter includes a document if it satisfies any of the given filters.