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.assetmust 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 underflutter:, 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.pngKeep 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.