addEventListener<T extends Event> method Null safety

StreamSubscription<T> addEventListener<T extends Event>(
  1. String eventType,
  2. EventListener<T> eventListener,
  3. {bool useCapture = false,
  4. int priority = 0}

Adds an event listener to receive events.

This style of adding an event listener is used for an easy migration from legacy ActionScript3 code to Dart code. In pure Dart code you should consider using the Dart style of adding event listenes like this:


// ActionScript3 style
sprite.addEventListener(Event.ADDED_TO_STAGE, _onAddedToStage);
sprite.addEventListener(MouseEvent.Click, _onMouseClick, useCapture: true);
sprite.addEventListener("CustomEvent", _onCustomEvent);

// Dart style


StreamSubscription<T> addEventListener<T extends Event>(
    String eventType, EventListener<T> eventListener,
    {bool useCapture = false, int priority = 0}) {
  final eventStream = on<T>(eventType);
  return eventStream._subscribe(eventListener, useCapture, priority);