Display Image from URL in Flutter – Image.network()
In this tutorial, we will learn how to display an image from URL, in Flutter Application.
In Flutter, you can display an image from different possible sources. To display an image from URL, you may use Image.network() constructor of Image class.
Sample Code Snippet
Following is a sample code snippet to display an image from the URL https://googleflutter.com/sample_image.jpg
.
Image.network('https://googleflutter.com/sample_image.jpg'),
Following is a list of supported Image formats.
- JPEG
- PNG
- GIF
- Animated GIF
- WebP
- Animated WebP
- BMP
- WBMP
Example
This is an example Flutter application to demonstrate how to display an image in your Flutter application.
To recreate this example application, create a Flutter application and replace main.dart with the following code.
main.dart
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: MyApp(),
));
}
class MyApp extends StatefulWidget {
@override
_State createState() => _State();
}
class _State extends State<MyApp> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Flutter Tutorial - googleflutter.com'),
),
body: Center(
child: Column(children: <Widget>[
Text('Welcome to Flutter Tutorial on Image'),
Image.network('https://googleflutter.com/sample_image.jpg'),
])),
);
}
}
When you run this application on an Android Device or Emulator, you should something similar to the following screenshot.
Summary
In this Flutter Tutorial, we learned how to display an image in Flutter UI Application from URL via network.