How to Show an Image from a URL in Flutter

In this blog post, I will tell you how to display an image which loads from the internet in your Flutter app.

This flutter image example uses Image widget with Image.network constructor. Go through the code of main.dart given below:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());


class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Flutter Image Example'),
        ),
        //calling MyBody class
        body: Center(child:Image.network(
          'https://cdn.pixabay.com/photo/2015/03/26/09/41/phone-690091_960_720.jpg',
          height: 400, width:  400,
        ),),
      ),
    );
  }
}

The output of flutter image example is as given in the screenshot below:

I am showing an image from pixabay website with height and width of 400 pixels.

Leave a Comment

Your email address will not be published. Required fields are marked *