isCloneOf method
- ImageInfo other
Whether this ImageInfo is a clone of the other
.
This method is a convenience wrapper for ui.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 (in this case in a
setter).
link
ImageInfo? get imageInfo => _imageInfo;
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;
}
// It is a new image. Dispose of the old one and take a reference
// to the new one.
_imageInfo?.dispose();
_imageInfo = value;
// Perform work to determine size, paint the image, etc.
// ...
}
Implementation
bool isCloneOf(ImageInfo other) {
return other.image.isCloneOf(image)
&& scale == scale
&& other.debugLabel == debugLabel;
}