subscribeToEvent function Null safety

int subscribeToEvent(
  1. String eventName,
  2. dynamic callback(
    1. Event
    )
)

Subscribes to global Event such as 'pageLoaded', with a callback function

Implementation

int subscribeToEvent(String eventName, Function(Event) callback) {
  var event = Event(eventName, callback, '', 0);
  if(!simpleEvents.containsKey(eventName)){
    simpleEvents[eventName] = List<Event>.empty(growable: true);
  }
  simpleEvents[eventName] ??= List<Event>.empty(growable: true);
  simpleEvents[eventName]?.add(event);
  var length = simpleEvents[eventName]?.length;
  length ??= 0;
  return length - 1;
}