ImageForCanvas<T> class

IMPORTANT: See example file: main_image_for_canvas.dart

Use this ImageForCanvas class if you want to create images to use with Canvas. It will use the regular image cache from Flutter, and works with NetworkToFileImage provider, or any other image providers.

In more detail:

ImageProviders can't be used directly with the Canvas object of the paint method of a CustomPainter. Use this to download and save in the cache images to use with canvas.

For example: Suppose a User object that contains url and filename properties.

var imageForCanvas = ImageForCanvas<User>(
       imageProviderSupplier: (User user) =>
          NetworkToFileImage(file: user.file, url: user.url),
       keySupplier: (User user) => user.filename,
       loadCallback: (image, obj, key) => setState((){}),
     );

// While the image is downloading, this will return null.
var myImage = imageForCanvas.image(user);

if (myImage != null) {
   canvas.drawImage(myImage, ...);
   }

Constructors

ImageForCanvas({required ImageProvider<Object>? imageProviderSupplier(T obj), required LoadCallback<T>? loadCallback, Object keySupplier(T obj)?})

Properties

hashCode int
The hash code for this object.
no setterinherited
imageProviderSupplier ImageProvider<Object>? Function(T obj)
final
keySupplier → (Object Function(T obj)?)
final
loadCallback LoadCallback<T>?
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clearInternalCache() → void
image(T obj) Image?
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited