OnlineManager class Managers

Tracks whether the device believes it has a network connection.

Fetches and mutations under NetworkMode.online (the default) do not start while offline: they pause. When this manager reports online again, a mounted QueryClient (see QueryClient.mount) continues them, resumes paused mutations and refetches stale observed queries (the refetchOnReconnect option). A client that is not mounted does not listen, and what is paused stays paused.

Each client owns one, as QueryClient.onlineManager. The default is "online". Nothing is installed for you: report connectivity with setOnline, or install an adapter with setEventListener. The Flutter binding takes an optional Stream<bool> and depends on no connectivity package; a connectivity_plus stream, which reports a link rather than reachability, is the usual source.

client.onlineManager.setEventListener((setOnline) {
  final subscription = connectivityStream.listen(setOnline);
  return subscription.cancel;
});

// Or by hand, e.g. in a test:
client.onlineManager.setOnline(false);

Constructors

OnlineManager()
Creates a manager that reports online until setOnline or an adapter installed with setEventListener says otherwise.

Properties

hashCode → int
The hash code for this object.
no setterinherited
hasListeners → bool
Whether at least one listener is registered — what tells a manager to keep its platform event source installed.
no setterinherited
listeners → List<void Function(bool online)>
The listeners currently registered, in subscription order, read-only. Subclasses notifying by hand iterate this; notifyListeners is the loop that skips a listener an earlier one removed.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

isOnline() → bool
Whether the device is currently believed to be online. Reads the value last passed to setOnline, or true when nothing has been set; the retryer consults it before starting and before resuming a paused fetch.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners(void deliver(void listener(bool online))) → void
Calls every listener through deliver. See ListenerRegistry.notify: a listener an earlier one removed is skipped, and a throw is reported to the zone rather than escaping into whatever produced the event.
inherited
onSubscribe() → void
Reinstalls the event source the last listener's departure tore down.
onUnsubscribe() → void
Called after every unsubscribe. Subclasses use it to tear their event source down once hasListeners turns false.
setEventListener(OnlineSetup setup) → void
Replaces the source of connectivity events.
setOnline(bool online) → void
Sets the online state by hand. A change notifies the listeners — going online is what resumes paused work in a mounted client; setting the value it already has does nothing.
subscribe(void listener(bool online)) → void Function()
Registers listener and returns the function that removes it again.
inherited
toString() → String
A string representation of this object.
inherited

Operators

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