addListener method

Event addListener(
  1. EventFunction listener
)

Adds a synchronous listener to the event.

Synchronous listeners are called immediately and should complete quickly. They are executed before any asynchronous listeners.

Parameters:

  • listener - The function to call when the event is emitted

Returns this Event instance for method chaining.

Example:

event.addListener((data) => print('Event: $data'))
     .addListener((data) => updateCounter());

Implementation

Event addListener(EventFunction listener) {
  _listeners.add(listener);
  return this;
}