notifyListeners method

  1. @override
  2. @protected
  3. @visibleForTesting
void notifyListeners([
  1. T? property
])
override

Notifies the appropriate listeners that property was changed. Implementers should ideally provide a property parameter. It is only optional for backwards compatibility with ChangeNotifier. Global listeners will be notified every time, even if property is null. Listeners for specific properties will only be notified if property is equal (operator==) to one of those properties. If property is not null, must be a single instance of T (typically a String).

Implementation

@override
@protected
@visibleForTesting
void notifyListeners([T? property]) {
  assert(_debugAssertNotDisposed());
  assert(property is! Iterable, 'notifyListeners() should only be called for one property at a time');

  // Always notify global listeners
  _notifyListeners(_globalListeners!, property);

  // If no property provided, exit
  if (property == null) {
    return;
  }

  // If listeners exist for this property, notify them.
  if (_propertyListeners!.containsKey(property)) {
    _notifyListeners(_propertyListeners![property]!, property);
  }
}