setNetworkStream method

void setNetworkStream(
  1. Stream<bool> stream
)

Set the network stream to listen for connectivity changes.

Cancels any previous subscription before attaching to the new stream, ensuring that calling this method more than once (e.g. after a hot-restart or test re-init) does not accumulate duplicate listeners.

Implementation

void setNetworkStream(Stream<bool> stream) {
  _networkSubscription?.cancel();
  _networkSubscription = stream.listen((isOnline) {
    if (isOnline) {
      process();
    }
  });
}