createConnectivityStateSubscribeFunction function

ConnectivityStateSubscribeFunction createConnectivityStateSubscribeFunction(
  1. Notifier notifier
)

Implementation

ConnectivityStateSubscribeFunction createConnectivityStateSubscribeFunction(
  Notifier notifier,
) {
  return (handler) {
    bool cancelled = false;
    void update(
      ConnectivityStateChangeNotification notification,
    ) {
      if (cancelled) return;
      handler(notification.connectivityState);
    }

    final unsubscribe = notifier.subscribeToConnectivityStateChanges(update);

    return () {
      cancelled = true;
      unsubscribe();
    };
  };
}