MutationStateController<TSelected> class Collections

A value selected from every mutation in the cache that matches the filters, as a ValueListenable of a list — one entry per mutation, in the order they were added.

What it is for: showing mutations from somewhere other than where they were started — a "saving…" badge in the app bar, a pending row in a list for a write started on another screen, a count of writes in flight. It is also the mutation side's answer to IsFetchingController: a controller filtered on MutationStatus.pending counts the mutations running.

final saving = MutationStateController<int>(
  client,
  filters: const MutationFilters(status: MutationStatus.pending),
  select: (mutation) => 1,
);

ValueListenableBuilder<List<int>>(
  valueListenable: saving,
  builder: (context, pending, _) => pending.isEmpty
      ? const SizedBox()
      : Text('Saving ${pending.length}…'),
);

// When done:
saving.dispose();

Subscribed to the mutation cache only while something listens, and listeners are told only when the selection changed element by element. select runs over every matching mutation on every cache change, so keep it cheap. Use MutationStateController.typed to select from mutations of one type, with their variables and data typed.

Inheritance
Implemented types

Constructors

MutationStateController(QueryClient client, {MutationFilters filters = const MutationFilters(), required MutationStateSelect<TSelected> select})
Creates a selection over client's mutation cache.

Properties

client → QueryClient
The client whose mutations are selected.
final
hashCode → int
The hash code for this object.
no setterinherited
hasListeners → bool
Whether any listeners are currently registered.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
value → List<TSelected>
The current value of the object.
no setteroverride

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
override
dispose() → void
Discards any resources used by the object.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
override
setOptions({MutationFilters? filters, MutationStateSelect<TSelected>? select}) → void
Replaces the filters and/or selector, keeping the same client. Either left null stays as it was. The selection is recomputed at once, and listeners are told when it changed.
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}) → MutationStateController<TSelected>
A selection over the mutations of one type, select receiving them typed — see MutationStateObserver.typed. The types usually come from select's parameter, and a type left as Object? matches anything.