addReferenceV2 method
Called when a ScalableImageSource is referenced,
e.g. in a stateful widget's State object's initState
method.
Returns a Future for the scalable image.
Application code where a cache is present should use the returned value, and not use ScalableImageSource.createSI directly.
src
The source of the scalable image
Implementation
FutureOr<ScalableImage> addReferenceV2(ScalableImageSource src) {
_CacheEntry? e = _canonicalized[src];
if (e == null) {
e = _CacheEntry(src, src.createSI());
_canonicalized[src] = e;
} else {
_verifyCorrectHash(src, e._siSrc!);
if (e._lessRecent != null) {
// Now it's referenced, so we take it off the LRU list.
assert(e._refCount == 0);
e._lessRecent!._moreRecent = e._moreRecent;
e._moreRecent!._lessRecent = e._lessRecent;
e._lessRecent = e._moreRecent = null;
} else {
assert(e._refCount > 0);
}
}
e._refCount++;
return e._si!;
}