register method

dynamic register(
  1. EventTypes type,
  2. OnEventCallback callback, {
  3. int? priority,
})

Register a listener on an event type

To have a widget's EventManager listen to an Event you must register a listener in the didChangeDependencies() and didUpdateWidget() in its _ViewState

Implementation

register(EventTypes type, OnEventCallback callback, {int? priority}) {
  if (!listeners.containsKey(type)) listeners[type] = [];
  int i = listeners[type]!.length;
  if ((priority != null) && (priority >= 0) && (priority <= i)) i = priority;
  if (!listeners[type]!.contains(callback)) {
    listeners[type]!.insert(i, callback);
  }
}