Skip to the workspace
Pebellslearn by building
Working with Assets  ›  Lesson

Images

Images 12 minImage files must be declared under flutter assets in pubspec.yaml before Image.asset can load them, and resolution folders such as 2.0x let Flutter pick a sharper version for denser screens.

flutter / Images

Explore each scene at your own pace.

01 · The rule

The rule

Images

Sprout should show a small photo of each plant: a fern, a cactus, a snake plant. Those pictures ship inside the app, so they work offline. Flutter only bundles files you name in pubspec.yaml; anything else in the project folder is left out of the build.

The rule

Declare it in pubspec, then load it by the same path.

flutter:
  uses-material-design: true
  assets:
    - assets/images/
    - assets/images/plants/
Image.asset('assets/images/plants/fern.png', width: 64, height: 64)
  • Paths are relative to the project root, and the one in Image.asset must match the file exactly, including case.
  • Listing a folder (ending in /) includes every file directly inside it, but not its subfolders. Each subfolder needs its own line.
  • YAML is strict about indentation: assets: sits under flutter:, and each entry is a dash one level deeper.
  • After editing pubspec.yaml, stop and rerun the app. A hot reload does not pick up new asset entries.

Sharper images on dense screens. Add higher-resolution copies in folders named by pixel ratio:

assets/images/plants/fern.png        (1x)
assets/images/plants/2.0x/fern.png
assets/images/plants/3.0x/fern.png

Keep loading 'assets/images/plants/fern.png'. On a phone with a 3x screen, Flutter picks the 3.0x copy automatically.

Images from the internet use Image.network(url) instead, and need no pubspec entry, but they need a connection.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.