triggerEvent function Null safety

void triggerEvent(
  1. String eventName,
  2. [String payload = '',
  3. Map<String, dynamic> data = const {}]
)

Triggers global Event such as 'pageLoaded', with payload

Implementation

void triggerEvent(String eventName, [String payload = '', Map<String, dynamic> data = const {}]) {
  //if(eventName == 'pageLoaded'){ removeAllComponentEvents(); } // remove all component events from previous page
  if (simpleEvents.containsKey(eventName)) {
    int? length = simpleEvents[eventName]?.length;
    length ??= 0;
    for(int i=0 ;i<length; i++){
      Event evt = simpleEvents[eventName]![i];
      if(data.containsKey('target')) evt.target = data['target'];
      evt.payload = payload;
      evt.callback(evt);
    }
  }
}