removeListener method

void removeListener (
  1. void listener(
      )
    )

    Removes a listener to contact database changes.

    Because of limitations both on iOS and on Android (see https://www.grokkingandroid.com/use-contentobserver-to-listen-to-changes/) it's not possible to tell which kind of change happened and on which contacts. It only notifies that something changed in the contacts database.

    Implementation

    static void removeListener(void Function() listener) {
      if (_eventSubscription != null) {
        _eventSubscription.cancel();
      }
      _eventSubscribers.remove(listener);
      if (_eventSubscribers.isEmpty) {
        _eventSubscription = null;
      } else {
        final runAllListeners = (event) => _eventSubscribers.forEach((f) => f());
        _eventSubscription =
            _eventChannel.receiveBroadcastStream().listen(runAllListeners);
      }
    }