removeListener method

void removeListener(
  1. String eventName,
  2. EventCallback callback

Unsubscribe from getting any future events from emitter. This mechanism uses event name and callback to unsubscribe from all possible events. eventName - Event name for the subscription. callback - EventCallback used when registering subscription using on function.


void removeListener(String eventName, EventCallback callback) {
  if (eventName.trim().isEmpty) {
    throw ArgumentError.notNull('eventName');

  // Check if listeners have the specific event already registered.
  // if so, then check for the callback registration.

  if (_listeners.containsKey(eventName)) {
    var subs = _listeners[eventName]!;
    subs.removeWhere((element) =>
        element.eventName == eventName && element.callback == callback);