onChange method

Future<void> Function() onChange (
  1. Function listener
)

//////////////////////////////////////////////// LISTENING TO DB CHANGES /// //////////////////////////////////////////////// Listens to contact database changes and executes callback function.

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 something changed in the contacts database.

listener must be a parameterless function.

The return value is a function (returning Future<void>) that cancels the subscription.

Implementation

/// Listens to contact database changes and executes callback function.
///
/// 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 something changed in the contacts database.
///
/// [listener] must be a parameterless function.
///
/// The return value is a function (returning [Future<void>]) that cancels the
/// subscription.
static Future<void> Function() onChange(Function listener) {
  var subscription =
      _eventChannel.receiveBroadcastStream().listen((event) => listener());
  return () => subscription.cancel();
}