QueryFilters class final Filters

Selects a set of queries from the cache.

Passed as filters: to the client's bulk operations — invalidateQueries, refetchQueries, cancelQueries, removeQueries, resetQueries, isFetching and the rest — and to QueryCache.find and QueryCache.findAll. A query must match every field that is set:

  • queryKey — the key, as a prefix unless exact is true.
  • exact — whether queryKey must match the whole key.
  • type — observed queries, unobserved ones, or both.
  • stale — stale or fresh queries.
  • fetchStatus — fetching, paused or idle queries.
  • status — pending, successful or failed queries.
  • predicate — any test of your own over the query.

Every field is optional and null means "do not filter on this", so an empty QueryFilters() matches every query in the cache.

// Every query whose key starts with 'todos': ['todos'],
// ['todos', 3], ['todos', {'done': true}], ...
await client.invalidateQueries(
  filters: QueryFilters(queryKey: QueryKey(['todos'])),
);

// Only the one query keyed exactly ['todos'].
client.removeQueries(
  filters: QueryFilters(queryKey: QueryKey(['todos']), exact: true),
);
Annotations
  • @immutable

Constructors

QueryFilters({QueryKey? queryKey, bool? exact, QueryTypeFilter? type, bool? stale, FetchStatus? fetchStatus, QueryStatus? status, bool predicate(Query<Object?> query)?})
Every argument is optional; leave one unset to not filter on it.
const

Properties

exact → bool?
Whether queryKey must equal the whole key rather than a prefix of it.
final
fetchStatus → FetchStatus?
Matches queries in this fetch status: fetching, paused or idle. Unset ignores it.
final
hashCode → int
The hash code for this object.
no setterinherited
predicate → bool Function(Query<Object?> query)?
A test of your own, run on each query that passed the other fields. Unset accepts every query.
final
queryKey → QueryKey?
The key to match. By default it is a prefix: QueryKey(['todos']) matches QueryKey(['todos']) and QueryKey(['todos', 3]) alike. Set exact to match only the key itself. Unset matches every key.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
stale → bool?
Matches queries whose isStale() is this value: true for stale queries, false for fresh ones. Unset ignores staleness.
final
status → QueryStatus?
Matches queries in this status: pending, success or error. Unset ignores it.
final
type → QueryTypeFilter?
Restricts to active queries (at least one enabled observer), inactive ones, or both; see QueryTypeFilter. Unset means both.
final

Methods

matches(Query<Object?> query, {bool exactByDefault = false}) → bool
Whether query matches. exactByDefault is what an unset exact means to the caller: prefix for the bulk operations, exact for find.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited