onEnabledChange static method

void onEnabledChange(
  1. dynamic callback(
    1. bool
    )
)

Subscribe to changes in plugin State.enabled.

Fired when the plugin's State.enabled changes. For example, executing start and stop will cause the onEnabledChnage event to fire. This event is primarily designed for use with the configuration option Config.stopAfterElapsedMinutes, which automatically executes the plugin's stop method.

Example

BackgroundGeolocation.onEnabledChange'((bool isEnabled) {
  print('[onEnabledChanged] isEnabled? ${isEnabled}');
});

Implementation

static void onEnabledChange(Function(bool) callback) {
  if (_eventsEnabledChange == null) {
    _eventsEnabledChange = _eventChannelEnabledChange
        .receiveBroadcastStream()
        .map((dynamic enabled) => enabled as bool);
  }
  _registerSubscription(_eventsEnabledChange!.listen(callback), callback);
}