ExactAssetImage class

Fetches an image from an AssetBundle, associating it with the given scale.

This implementation requires an explicit final assetName and scale on construction, and ignores the device pixel ratio and size in the configuration passed into resolve. For a resolution-aware variant that uses the configuration to pick an appropriate image based on the device pixel ratio and size, see AssetImage.

Fetching assets

When fetching an image provided by the app itself, use the assetName argument to name the asset to choose. For instance, consider a directory icons with an image heart.png. First, the pubspec.yaml of the project should specify its assets in the flutter section:

    - icons/heart.png

Then, to fetch the image and associate it with scale 1.5, use

AssetImage('icons/heart.png', scale: 1.5)

Assets in packages

To fetch an asset from a package, the package argument must be provided. For instance, suppose the structure above is inside a package called my_icons. Then to fetch the image, use:

AssetImage('icons/heart.png', scale: 1.5, package: 'my_icons')

Assets used by the package itself should also be fetched using the package argument as above.

If the desired asset is specified in the pubspec.yaml of the package, it is bundled automatically with the app. In particular, assets used by the package itself must be specified in its pubspec.yaml.

A package can also choose to have assets in its 'lib/' folder that are not specified in its pubspec.yaml. In this case for those images to be bundled, the app has to specify which ones to include. For instance a package named fancy_backgrounds could have:


To include, say the first image, the pubspec.yaml of the app should specify it in the assets section:

    - packages/fancy_backgrounds/backgrounds/background1.png

The lib/ is implied, so it should not be included in the asset path.

See also:



ExactAssetImage(String assetName, { double scale: 1.0, AssetBundle bundle, String package })
Creates an object that fetches the given image from an asset bundle. [...]


assetName String
The name of the asset.
bundle AssetBundle
The bundle from which the image will be obtained. [...]
hashCode int
The hash code for this object. [...]
read-only, override
keyName String
The key to use to obtain the resource from the bundle. This is the argument passed to AssetBundle.load.
package String
The name of the package from which the image is included. See the documentation for the ExactAssetImage class itself for details.
scale double
The scale to place in the ImageInfo object of the image.
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited


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.
evict({ImageCache cache, ImageConfiguration configuration: ImageConfiguration.empty }) Future<bool>
Evicts an entry from the image cache. [...]
load(AssetBundleImageKey key) ImageStreamCompleter
Converts a key into an ImageStreamCompleter, and begins fetching the image using loadAsync.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
resolve(ImageConfiguration configuration) ImageStream
Resolves this image provider using the given configuration, returning an ImageStream. [...]


operator ==(dynamic other) bool
The equality operator. [...]