notifyListeners method Null safety

void notifyListeners()

Calls all the listeners.

If listeners are added or removed during this function, the modifications will not change which listeners are called during this iteration.

Implementation

void notifyListeners() {
  final List<VoidCallback> localListeners = List<VoidCallback>.from(_listeners);
  for (final VoidCallback listener in localListeners) {
    InformationCollector? collector;
    assert(() {
      collector = () sync* {
        yield DiagnosticsProperty<AnimationLocalListenersMixin>(
          'The $runtimeType notifying listeners was',
          this,
          style: DiagnosticsTreeStyle.errorProperty,
        );
      };
      return true;
    }());
    try {
      if (_listeners.contains(listener))
        listener();
    } catch (exception, stack) {
      FlutterError.reportError(FlutterErrorDetails(
        exception: exception,
        stack: stack,
        library: 'animation library',
        context: ErrorDescription('while notifying listeners for $runtimeType'),
        informationCollector: collector,
      ));
    }
  }
}