A widget that displays an image.
Several constructors are provided for the various ways that an image can be specified:
- Image.new, for obtaining an image from an ImageProvider.
- Image.asset, for obtaining an image from an AssetBundle using a key.
- Image.network, for obtaining an image from a URL.
- Image.file, for obtaining an image from a File.
- Image.memory, for obtaining an image from a Uint8List.
The following image formats are supported: JPEG, PNG, GIF, Animated GIF, WebP, Animated WebP, BMP, and WBMP. Additional formats may be supported by the underlying platform. Flutter will attempt to call platform API to decode unrecognized formats, and if the platform API supports decoding the image Flutter will be able to render it.
To automatically perform pixel-density-aware asset resolution, specify the image using an AssetImage and make sure that a MaterialApp, WidgetsApp, or MediaQuery widget exists above the Image widget in the widget tree.
class ExImage extends StatelessWidget {
const ExImage({super.key});
@override
Widget build(BuildContext context) {
return Container(
width: 300,
height: 300,
color: Colors.blue.shade100,
child: Image(
// image: NetworkImage(
// "https://cdn.pixabay.com/photo/2023/08/05/23/40/bird-8171927_1280.jpg",
// ),
image: AssetImage("assets/image/food0.png"),
// fit: BoxFit.cover,
),
);
}
}