Fetches an image from an AssetBundle, having determined the exact image to use based on the context.

Given a main asset and a set of variants, AssetImage chooses the most appropriate asset for the current context, based on the device pixel ratio and size given in the configuration passed to resolve.

To show a specific image from a bundle without any asset resolution, use an AssetBundleImageProvider.

Naming assets for matching with different pixel densities

Main assets are presumed to match a nominal pixel ratio of 1.0. To specify assets targeting different pixel ratios, place the variant assets in the application bundle under subdirectories named in the form "Nx", where N is the nominal device pixel ratio for that asset.

For example, suppose an application wants to use an icon named "heart.png". This icon has representations at 1.0 (the main icon), as well as 1.5 and 2.0 pixel ratios (variants). The asset bundle should then contain the following assets:

heart.png
1.5x/heart.png
2.0x/heart.png

On a device with a 1.0 device pixel ratio, the image chosen would be heart.png; on a device with a 1.3 device pixel ratio, the image chosen would be 1.5x/heart.png.

The directory level of the asset does not matter as long as the variants are at the equivalent level; that is, the following is also a valid bundle structure:

icons/heart.png
icons/1.5x/heart.png
icons/2.0x/heart.png
Inheritance

Constructors

AssetImage(String name, { AssetBundle bundle })

Creates an object that fetches an image from an asset bundle.

Properties

bundle AssetBundle

The bundle from which the image will be obtained.

read-only
hashCode int

read-only
name String

The name of the main asset from the set of images to chose from. See the documentation for the AssetImage class itself for details.

read-only
runtimeType Type

A representation of the runtime type of the object.

read-only, inherited

Operators

operator ==(other) bool

The equality operator.

Methods

obtainKey(ImageConfiguration configuration) Future<AssetBundleImageKey>

Converts an ImageProvider's settings plus an ImageConfiguration to a key that describes the precise image to load.

toString() String

Returns a string representation of this object.

decodeImage(ByteData data) Future<Image>

Converts raw image data from a ByteData buffer into a decoded ui.Image which can be passed to a Canvas.

inherited
load(AssetBundleImageKey key) ImageStreamCompleter

Converts a key into an ImageStreamCompleter, and begins fetching the image using loadAsync.

inherited
loadAsync(AssetBundleImageKey key) Future<ImageInfo>

Fetches the image from the asset bundle, decodes it, and returns a corresponding ImageInfo object.

inherited
noSuchMethod(Invocation invocation) → dynamic

Invoked when a non-existent method or property is accessed.

inherited
resolve(ImageConfiguration configuration) ImageStream

Resolves this image provider using the given configuration, returning an ImageStream.

inherited