addListener static method

void addListener(
  1. void listener()
)

Listens 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 addListener(void Function() listener) {
  if (_eventSubscription != null) {
    _eventSubscription!.cancel();
  }
  _eventSubscribers.add(listener);
  final runAllListeners = (event) => _eventSubscribers.forEach((f) => f());
  _eventSubscription =
      _eventChannel.receiveBroadcastStream().listen(runAllListeners);
}