addListener method

void addListener (ImageListener listener, { ImageErrorListener onError })

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

If the assigned completer 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.

An ImageErrorListener can also optionally be added along with the listener. If an error occurred, onError will be called instead of listener.

Many listeners can have the same onError and one listener can also have multiple onError by invoking addListener multiple times with a different onError each time.

Implementation

void addListener(ImageListener listener, { ImageErrorListener onError }) {
  if (_completer != null)
    return _completer.addListener(listener, onError: onError);
  _listeners ??= <_ImageListenerPair>[];
  _listeners.add(_ImageListenerPair(listener, onError));
}