MutationStateObserver<TSelected> class Observers

Watches a selection over every mutation in the cache, in submission order — not just the ones one observer started.

Use it where one widget needs to know about mutations started elsewhere: the variables of every pending "add todo" to show optimistic rows, a count of saves in flight, the last error of any upload. filters pick the mutations (by key, status or predicate) and select turns each into a value; currentResult is the list of those values.

final pendingTitles = MutationStateObserver<Object?>(
  client,
  filters: MutationFilters(
    mutationKey: QueryKey(['todos', 'add']),
    status: MutationStatus.pending,
  ),
  select: (mutation) => mutation.state.variables,
);
final unsubscribe = pendingTitles.subscribe(print);
// Later:
unsubscribe();
pendingTitles.destroy();

typed gives select the mutations with their declared types.

It subscribes to the cache only while it has listeners. Selection uses structural sharing, so equivalent lists and maps do not notify again. (TanStack Query: useMutationState.)

Constructors

MutationStateObserver(QueryClient client, {MutationFilters filters = const MutationFilters(), required MutationStateSelect<TSelected> select})
Creates a selection, readable immediately through currentResult.

Properties

currentResult → List<TSelected>
The selected values. Reads without listeners refresh from the cache.
no setter
hashCode → int
The hash code for this object.
no setterinherited
hasListeners → bool
Whether the observer currently follows cache events.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

destroy() → void
Removes all listeners and releases the cache subscription.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setOptions({MutationFilters? filters, MutationStateSelect<TSelected>? select}) → void
Replaces filters and/or selection and immediately recomputes the result. A typed observer keeps its type test — see there.
subscribe(void listener(List<TSelected>)) → void Function()
Registers a listener without delivering an initial snapshot.
toString() → String
A string representation of this object.
inherited

Operators

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

Static Methods

typed<TData, TVariables, TOnMutateResult, TSelected>(QueryClient client, {MutationFilters filters = const MutationFilters(), required TypedMutationStateSelect<TData, TVariables, TOnMutateResult, TSelected> select}) → MutationStateObserver<TSelected>
A selection over the mutations of one type, select receiving them typed — no cast to get at state.variables. (TanStack Query's useMutationState has only the untyped form.)