onConnectivityChange static method

void onConnectivityChange(
  1. dynamic callback(
    1. ConnectivityChangeEvent
    )
)

Subscribe to changes in network connectivity.

Fired when the state of the device's network-connectivity changes (enabled -> disabled and vice-versa). By default, the plugin will automatically fire a connectivitychange event with the current state network-connectivity whenever the start method is executed.

Example

BackgroundGeolocation.oConnectivityChange((ConnectivityChangeEvent event) {
  print('[onConnectivityChange] ${event}');
});

Implementation

static void onConnectivityChange(Function(ConnectivityChangeEvent) callback) {
  if (_eventsConnectivityChange == null) {
    _eventsConnectivityChange = _eventChannelConnectivityChange
        .receiveBroadcastStream()
        .map((dynamic event) {
      return ConnectivityChangeEvent(event['connected']);
    });
  }
  _registerSubscription(
      _eventsConnectivityChange!.listen(callback), callback);
}