on<T extends Event> method Null safety

EventStream<T> on<T extends Event>(
  1. String eventType
)

Returns an event stream of type eventType.

This accessor should only be used when an explicit accessor is not available, e.g. for custom events:

sprite.onAddedToStage.listen(_onAddedToStage);
sprite.onMouseClick.capture(_onMouseClick);
sprite.on("CustomEvent").listen(_onCustomEvent);

Implementation

EventStream<T> on<T extends Event>(String eventType) {
  var eventStream = _eventStreams[eventType];
  if (eventStream == null) {
    eventStream = EventStream<T>._(this, eventType);
    _eventStreams[eventType] = eventStream;
  }

  return eventStream as EventStream<T>;
}