whereFilter method
Creates and returns a new Query with the additional filter that documents should satisfy the relation constraint(s) provided.
This function returns a new (immutable) instance of the Query (rather than modify the existing instance) to impose the filter.
filter
A unary or composite filter to apply to the Query.
final collectionRef = firestore.collection('col');
collectionRef.where(Filter.and(Filter.where('foo', WhereFilter.equal, 'bar'), Filter.where('foo', WhereFilter.notEqual, 'baz'))).get()
.then((querySnapshot) {
querySnapshot.forEach((documentSnapshot) {
print('Found document at ${documentSnapshot.ref.path}');
});
});
Implementation
Query<T> whereFilter(Filter filter) {
if (_queryOptions.startAt != null || _queryOptions.endAt != null) {
throw ArgumentError(
'Cannot specify a where() filter after calling '
'startAt(), startAfter(), endBefore() or endAt().',
);
}
final parsedFilter = _parseFilter(filter);
if (parsedFilter.filters.isEmpty) {
// Return the existing query if not adding any more filters (e.g. an empty composite filter).
return this;
}
final options = _queryOptions.copyWith(
filters: [..._queryOptions.filters, parsedFilter],
);
return Query<T>._(
firestore: firestore,
queryOptions: options,
);
}