addListener method

void addListener(
  1. PictureListener listener, {
  2. PictureErrorListener? onError,
})

Adds a listener callback that is called whenever a new concrete PictureInfo object is available. If a concrete image is already available, this object will call the listener synchronously.

If the PictureStreamCompleter completes multiple images over its lifetime, this listener will fire multiple times.

The listener will be passed a flag indicating whether a synchronous call occurred. If the listener is added within a render object paint function, then use this flag to avoid calling RenderObject.markNeedsPaint during a paint.

Implementation

void addListener(PictureListener listener, {PictureErrorListener? onError}) {
  _listeners.add(_PictureListenerPair(listener, onError));
  if (_current != null) {
    try {
      listener(_current, true);
    } catch (exception, stack) {
      _handleImageError(
        ErrorDescription('by a synchronously-called image listener'),
        exception,
        stack,
      );
    }
  }
}