notify method

void notify (
  1. String eventName,
  2. [Map<String, dynamic> args]
)

Notify each subscriber that the specified named event has occured. An optional map of arguments can be attached to the notification e.g. myEventNotifier.notify('valueChanged', {'age': 32);

Implementation

void notify(String eventName, [Map<String, dynamic> args]) {
  // ignore if no subscribers
  if (!_eventMap.containsKey(eventName)) return;

  // Schedule a microtask to debounce multiple changes that can occur all at once.
  if (_microtaskVersion == _version) {
    _microtaskVersion++;
    scheduleMicrotask(() {
      _version++;
      _microtaskVersion = _version;

      // Convert the Set to a List before executing each callback. This
      // prevents errors that can arise if a callback removes itself during invocation
      try {
        _eventMap[eventName].toList().forEach((NotificationCallback callback) => callback(args));
      } on NoSuchMethodError {
        throw NotifyException(
            'an argument expected by a subscriber, was not included in the notification for event "$eventName"',
            'notify');
      }
    });
  }
}