In this example, I will share how to display images from the internet in Flutter Displaying images is fundamental for most mobile apps. Flutter provides the Image widget to display different types of images.
To work with images from a URL, use the Image.network() constructor.
1 2 3 | Image.network( 'https://picsum.photos/250?image=9', ) |
One useful thing about the Image widget: It supports animated gifs.
1 2 3 | Image.network( 'https://github.com/flutter/plugins/raw/master/packages/video_player/doc/demo_ipod.gif?raw=true', ); |
Here is a complete example of display images from the internet:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { var title = 'Web Images'; return MaterialApp( title: title, home: Scaffold( appBar: AppBar( title: Text(title), ), body: Image.network( 'https://picsum.photos/250?image=9', ), ), ); } } |
Output
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.