isCloneOf method Null safety

bool isCloneOf(
  1. ImageInfo other
)

Whether this ImageInfo is a clone of the other.

This method is a convenience wrapper for Image.isCloneOf, and is useful for clients that are trying to determine whether new layout or painting logic is required when receiving a new image reference.

The following sample shows how to appropriately check whether the ImageInfo reference refers to new image data or not.
ImageInfo? _imageInfo;
set imageInfo (ImageInfo? value) {
  // If the image reference is exactly the same, do nothing.
  if (value == _imageInfo) {
    return;
  }
  // If it is a clone of the current reference, we must dispose of it and
  // can do so immediately. Since the underlying image has not changed,
  // We don't have any additional work to do here.
  if (value != null && _imageInfo != null && value.isCloneOf(_imageInfo!)) {
    value.dispose();
    return;
  }
  _imageInfo?.dispose();
  _imageInfo = value;
  // Perform work to determine size, or paint the image.
}

Implementation

bool isCloneOf(ImageInfo other) {
  return other.image.isCloneOf(image)
      && scale == scale
      && other.debugLabel == debugLabel;
}