ScalableImageCache class
An LRU cache of ScalableImage futures derived from ScalableImageSource
instances. A cache with a non-zero size could make
sense, for example, as part of the state of a
stateful widget that builds entries on demand, and that uses
ScalableImageWidget.fromSISource to asynchronously load scalable images.
See, for example, cache.dart
in the example
directory.
For a discussion of caching and potential reloading, see https://github.com/zathras/jovial_svg/issues/10.
If different caching semantics are desired, user code can implement
ScalableImageCache; ScalableImageWidget does not use any of its
private members. See also the demo_hive
application to see how
ScalableImageSource can be extended to load from a persistent cache.
Sample usage (see example/lib/cache.dart
for the full program):
class _HomePageState extends State<HomePage> {
ScalableImageCache _svgCache = ScalableImageCache(size: 70);
...
@override
Widget build(BuildContext context) {
return ...
ScalableImageWidget.fromSISource(
cache: _svgCache,
scale: 1000,
si: ScalableImageSource.fromSvgHttpUrl(widget.svgs[index]),
...),
...;
}
}
Constructors
- ScalableImageCache.new({int size = 0})
-
Create an image cache that holds up to
size
image sources. A ScalableImageCache will always keep referenced ScalableImageSource instances, even if this exceeds the cache size. In this case, no unreferenced images would be kept.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- size ↔ int
-
The size of the cache. If the cache holds unreferenced images, the total
number of images will be held to this size.
getter/setter pair
Methods
-
addReference(
ScalableImageSource src, {ScalableImage ifAvailableSync(ScalableImage)?}) → Future< ScalableImage> -
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. -
addReferenceV2(
ScalableImageSource src) → FutureOr< ScalableImage> -
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. -
forceReload(
ScalableImageSource src) → void - If the image referenced by src is in the cache, force it to be reloaded the next time it is used.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
removeReference(
ScalableImageSource src) → void - Called when a source is dereferenced, e.g. by a stateful widget's State object being disposed. Throws an exception if there had been no matching call to addReferenceV2 for this source.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited