notifyListeners method Null safety

  1. @protected
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

@protected
@pragma('vm:notify-debugger-on-exception')
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,
      ));
    }
  }
}