removeListener static method

bool removeListener(
  1. Function callback
)

Removes a single event-listener.

Example


// Create a Location callback:
Function(Location) callback = (Location location) {
  print('[My location callback] ${location}');
};
// Listen to the event:
BackgroundGeolocation.onLocation(callback);
.
.
.
// Later, use the original Function reference to remove the listener:
BackgroundGeolocation.removeListener(callback);

Implementation

static bool removeListener(Function callback) {
  _Subscription? found = _subscriptions
      .firstWhereOrNull((_Subscription item) => item.callback == callback);
  if (found != null) {
    found.subscription.cancel();
    _subscriptions.remove(found);
    return true;
  } else {
    return false;
  }
}