An image is asynchronous content when it comes from a network or an asset bundle. Its container should remain understandable while loading and when the image cannot be decoded.
Reserve the layout space
Choose a width, height or aspect ratio before the image arrives. Otherwise the surrounding content can jump when the intrinsic image dimensions become available.
Decide what failure means
A product photo can fall back to a placeholder. A diagram that carries the entire explanation needs a meaningful description or another way to access the information. Avoid a silent empty box.
The fragment below belongs inside a Flutter widget build method. It uses a local asset that must exist and be declared in pubspec.yaml.
Worked example
This is a focused code fragment. Place it in the class or file described above; it is not a complete standalone app.
SizedBox(width: 240, height: 160,
child: Image.asset('assets/images/workspace.png', fit: BoxFit.cover,
semanticLabel: 'A development workspace',
errorBuilder: (context, error, stack) => const Center(
child: Icon(Icons.broken_image_outlined, semanticLabel: 'Image unavailable')),
),
)
Read the result
The outer box fixes the layout footprint. BoxFit.cover can crop the image; use contain when the whole diagram must remain visible. The fallback is visible and has a semantic label.
Separate layout, decoding and meaning
The surrounding box answers how much space the image may occupy. The image provider answers where bytes come from. Decoding and painting turn those bytes into a visual result. A failure at the second or third step should not unexpectedly change the first step and move the entire page.
For a cover image, cropping can be acceptable; for a diagram, cropping may remove the exact information the reader needs. Choose fit behavior from the content, and supply an appropriate textual description when the image carries meaning. Decorative icons should not create repetitive spoken noise.
If a bundled image is missing, check the declared asset key, file-name case and directory declaration using assets and fonts . A network image instead needs a request/failure strategy and, on web, a service that permits the relevant browser access.
Practice and verification
Add a real image asset, run flutter pub get after editing pubspec.yaml and test a deliberately incorrect asset path. Confirm the surrounding layout keeps the same dimensions.