on method

Listener on(
  1. String event,
  2. Object? context,
  3. EventCallback callback
)

API to register for notification. It is mandatory to pass event name and callback parameters. event - Event name used for the subscription. A valid event name is mandatory. context - Context information, which need to be sent in all emitted events. callback - EventCallback function registered to receive events emitted from the publisher. A valid callback function is mandatory.

Implementation

Listener on(String event, Object? context, EventCallback callback) {
  if (event.trim().isEmpty) {
    throw ArgumentError.notNull('event');
  }

  var subs =
      // ignore: prefer_collection_literals
      _listeners.putIfAbsent(event, () => Set<Listener>());

  // Create new element.
  var listener = Listener.Default(event, context, callback);

// Apply cancellation callback.
  listener._cancelCallback = () {
    _removeListener(listener);
  };

  subs.add(listener);
  return listener;
}