ExactAssetPicture class

Fetches a picture 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 picture based on the device pixel ratio and size, see AssetPicture.

Fetching assets

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

flutter:
  assets:
    - icons/heart.png

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

AssetPicture('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 picture, use:

AssetPicture('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 pictures to be bundled, the app has to specify which ones to include. For instance a package named fancy_backgrounds could have:

lib/backgrounds/background1.png
lib/backgrounds/background2.png
lib/backgrounds/background3.png

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

 assets:
   - packages/fancy_backgrounds/backgrounds/background1.png

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

See also:

Inheritance

Constructors

ExactAssetPicture(PictureInfoDecoderBuilder<String> decoderBuilder, String assetName, {AssetBundle? bundle, String? package, ColorFilter? colorFilter})
Creates an object that fetches the given picture from an asset bundle.

Properties

assetName String
The name of the asset.
final
bundle AssetBundle?
The bundle from which the picture will be obtained.
final
colorFilter ColorFilter?
The color filter to apply to the picture, if any.
finalinherited
decoder PictureInfoDecoder<String>
The PictureInfoDecoder to use for loading this picture.
getter/setter pairinherited
decoderBuilder PictureInfoDecoderBuilder<String>
The decoder builder to build a decoder when theme changes.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
keyName String
The key to use to obtain the resource from the bundle. This is the argument passed to AssetBundle.load.
no setter
package String?
The name of the package from which the picture is included. See the documentation for the ExactAssetPicture class itself for details.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
theme SvgTheme
The default theme used when parsing SVG elements.
getter/setter pairinherited

Methods

load(AssetBundlePictureKey key, {PictureErrorListener? onError}) PictureStreamCompleter
Converts a key into an PictureStreamCompleter, and begins fetching the picture using _loadAsync.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
obtainKey(PictureConfiguration picture) Future<AssetBundlePictureKey>
Converts a pictureProvider's settings plus a pictureConfiguration to a key that describes the precise picture to load.
override
resolve(PictureConfiguration picture, {PictureErrorListener? onError}) PictureStream
Resolves this Picture provider using the given configuration, returning an PictureStream.
inherited
toString() String
A string representation of this object.
override

Operators

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