removeComponentEvent function Null safety

void removeComponentEvent(
  1. Event evt
)

Removes component event

  • evt is Event returned by the subscribeToComponentEvent Example:
  removeComponentEvent(myEvent);

Implementation

void removeComponentEvent(Event evt) {
  bool? hasEvent = eventSubscriptions.containsKey(evt.eventName);
  if(hasEvent) hasEvent = eventSubscriptions[evt.eventName]?.containsKey(evt.componentName);
  hasEvent ??= false;
  if(hasEvent) hasEvent = eventSubscriptions[evt.eventName]?[evt.componentName]?.containsKey(evt.componentIndex);
  hasEvent ??= false;
  if (hasEvent) {
    int? length = eventSubscriptions[evt.eventName]?[evt.componentName]?[evt.componentIndex]?.length;
    length ??= 0;
    if (length < evt.id) {
      eventSubscriptions[evt.eventName]?[evt.componentName]?[evt.componentIndex]?.removeAt(evt.id);
    }
  }
}