Image in Flutter

The Image widget is used to display images in Flutter apps. It supports various image sources like:

  1. Asset images (Image.asset)
  2. Network images (Image.network)
  3. File images (Image.file)
  4. Memory images (Image.memory)

Source Code​

				
					Image.asset(
  'assets/images/logo.png',
  width: 100,
  height: 100,
  fit: BoxFit.cover,
)


//image load from Network

Image.network(
  'https://example.com/image.jpg',
  width: 150,
  height: 100,
  fit: BoxFit.cover,
  loadingBuilder: (context, child, loadingProgress) {
    if (loadingProgress == null) return child;
    return CircularProgressIndicator();
  },
  errorBuilder: (context, error, stackTrace) => Icon(Icons.error),
)

				
			

Ai Code Analizer

🎨 Important Properties

PropertyDescription
width / heightControls size of the image
fitHow the image should be inscribed (e.g., BoxFit.cover, contain)
alignmentAligns image within its space
color / colorBlendModeApply color filter or blending effect
loadingBuilderCustom loading indicator (for Image.network)
errorBuilderCustom error widget if image fails to load (network only)

📦BoxFit Options for fit:

BoxFit OptionEffect
coverFill space, crop if needed
containFit inside without cropping
fillStretch to fit both height and width
fitWidthFit width, crop vertically if needed
fitHeightFit height, crop horizontally if needed