NotifyManager class Managers

Batches cache notifications so one cascade of cache writes produces one round of listener calls.

Each client owns one, as QueryClient.notifyManager; most apps never touch it. Two differences from TanStack Query:

  • The default scheduler is scheduleMicrotask, not a zero-delay timer. It is faster, it is deterministic, and fake_async controls it.
  • This is an ordinary object rather than a module-level singleton, so a QueryClient can own one and tests are hermetic. A client constructed without one creates its own; apps that want a single shared queue pass NotifyManager.shared to every client.

A batch holds callbacks submitted through schedule or batchCalls until the outermost batch ends, then delivers them through the scheduler. Direct observer subscriptions, cache listeners and onQueryUpdate remain synchronous per dispatch. Wrap a subscription with batchCalls when its delivery should be deferred. A throwing callback in a queued batch is reported to the zone and does not discard later callbacks in that batch.

// Several writes; callbacks queued through `schedule` or `batchCalls`
// meanwhile are delivered in one round after the batch ends:
client.notifyManager.batch(() {
  client.setQueryData<int>(QueryKey(['a']), 1);
  client.setQueryData<int>(QueryKey(['b']), 2);
});

// A cache subscription whose calls are deferred and batched:
client.queryCache.subscribe(
  client.notifyManager.batchCalls((QueryCacheEvent event) => log(event)),
);

Constructors

NotifyManager()
Creates an independent queue with the default microtask scheduler.

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
scheduler → ScheduleFunction
The scheduler in force. A caller that installs one keeps this to put back when it goes away — a stale scheduler outliving whoever set it would keep deferring notifications to a frame that never comes.
no setter

Methods

batch<T>(T callback()) → T
Runs callback, holding every notification scheduled inside it until the outermost batch completes.
batchCalls<A>(void callback(A)) → void Function(A)
Wraps callback so that calling it schedules rather than runs it.
flush() → void
Delivers everything queued so far, through the scheduler. batch calls this when its outermost call ends; calling it by hand is rarely needed.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
schedule(void callback()) → void
Queues callback for the next flush, or runs it through the scheduler immediately when no batch is open.
setBatchNotifyFunction(BatchNotifyFunction fn) → void
Replaces how a whole batch is delivered; see BatchNotifyFunction.
setNotifyFunction(NotifyFunction fn) → void
Replaces how a single notification is delivered; see NotifyFunction.
setScheduler(ScheduleFunction fn) → void
Replaces when the next batch runs. The Flutter binding installs a build-phase-aware scheduler here.
toString() → String
A string representation of this object.
inherited

Operators

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

Static Properties

shared → NotifyManager
A process-wide instance, for batching across clients. Not the default: a client constructed without one creates its own.
final