Display Network Image in Flutter

Flutter has an Image widget to display different types of images. To display images from the internet, the Image.network() function is used.

Syntax: Image.netwok (source_URL)

Follow the below steps to display the images from the internet in your Flutter application:

Step 1: Create a new flutter application in the required directory using the below command:

flutter create <app_name>

create flutter app through cmd

Step 2: Now, delete the code from main.dart file to add your own code.



Step 3: Now, use the below code in the main.dart file and change the parameter of Image.network function as per you need.

Dart

filter_none

edit
close

play_arrow

link
brightness_4
code

import 'package:flutter/material.dart';
  
void main() {
  runApp(MyApp());
}
  
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Network Image',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
      debugShowCheckedModeBanner: false,
    );
  }
}
  
// setup a stateful widget
class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        
      // Design of the application
      appBar: AppBar(
        title:Text("GeeksforGeeks"),
        backgroundColor:Colors.green
      ),
      body: Padding(
        padding: const EdgeInsets.all(8.0),
        child: ListView(
          children:<Widget>[
            Padding(
              padding: const EdgeInsets.all(8.0),
                
              // Image.network(src)              
   
            ),
            Padding(
              padding: const EdgeInsets.all(8.0),
            ),
            Padding(
              padding: const EdgeInsets.all(8.0),
            )
          ]
        ),
      ),
    );
  }
}

chevron_right


Output:

network image display in flutter
network image display in flutter

Code Explanation:

  • Here we used the ListView to display images on the screen.
  • In Image.network(src), we have given the network image path (src is image path).
  • Finally, we used the width and height to resize the image.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

6


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.