In Flutter, an `
Image
` widget is used to display an image on the screen. It supports different image formats such as
JPEG, PNG, GIF, and
WebP.
Here is an example of how to use an `
Image
` widget:
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Image Widget')),
body: Center(
child: Image.network(
'https://example.com/images/my_image.jpg',
width: 200,
height: 200,
fit: BoxFit.cover,
),
),
);
}
}​
In this example, an `
Image
` widget is used to display an image from a network URL. The `
fit
` property is set to `
BoxFit.cover
` which means that the image will be scaled to cover the entire widget without distorting its aspect ratio. The
`width
` and `
height
` properties set the size of the image widget.
Flutter also provides other types of `
Image
` widgets such as `
Image.asset
` for loading images from the app's assets, `
Image.file
` for loading images from a file, and `
Image.memory
` for loading images from memory.