Assets: Loading assets

Loading assets

Your app can access its assets through an AssetBundle object.

The two main methods on an asset bundle allow you to load a string/text asset (loadString()) or an image/binary asset (load()) out of the bundle, given a logical key. The logical key maps to the path to the asset specified in the pubspec.yaml file at build time.

Loading text assets

Outside of a Widget context, or when a handle to an AssetBundle is not available, you can use rootBundle to directly load assets.

Loading images

  • Flutter can load resolution-appropriate images for the current device pixel ratio.
  • To load an image, use the AssetImage class in a widget’s build method.
  • AssetImage understands how to map a logical requested asset onto one that most closely matches the current device pixel ratio. In order for this mapping to work, assets should be arranged according to a particular directory structure:.

Assets: Loading assets — Structure map

Clickable & Draggable!

Assets: Loading assets — Related pages: