emit method

void emit(
  1. String event, [
  2. Object? sender,
  3. Object? data
])
inherited

API to emit events. event is a required parameter. If sender information is sent, it will be used to intimate user about it. event - What event needs to be emitted. sender - The sender who published the event. Ignore if not required. data - Data the event need to carry. Ignore this argument if no data needs to be sent.

Implementation

void emit(String event, [Object? sender, Object? data]) {
  if (event.trim().isEmpty) {
    throw ArgumentError.notNull('event');
  }

  if (_listeners.containsKey(event)) {
    var ev = Event(event, data, sender);
    var sublist = _listeners[event]!.toList();
    for (var i = 0; i < sublist.length; i++) {
      var item = sublist[i];
      item.callback(ev, item.context);
      if (ev.handled) {
        break;
      }
    }
  }
}