Working with images in Flutter : Complete Flutter Tutorial

As I had said in the previous posts, everything is a widget in Flutter, so for working images, we are going to use an image widget. So for understanding the concept of images in detail, we will be making I am Rich app.

Now that you are familiar with the basics of Flutter development, we can proceed with a core Android concept of Flutter that is images. As I had said in the previous posts, everything is a widget in Flutter, so for working images, we are going to use an image widget.
Flutter tutorial: Working with images in Flutter

To understand this concept better, let's make an app that consists of images. I checked out the play store and the easiest app I found was I am Rich app which does nothing and costs almost 999$. Some people even bought the app as an icon of being rich. All the app has is an image of a diamond. So for understanding the concept of images in detail, we will be making I am Rich app.

Working with images in Flutter


Open your Android studio, and start a new Flutter project. Enter all the details and click on Finish. Now you will get prebuilt code by Flutter team. Remove all the code except the first line and then start coding your app like we did in the previous post. 

Today we will go into more detail and first give the title to our app. Code your way till scaffold, by adding run app, MaterialApp, and Scaffold into the app. Now as I said, all the widgets like title bar come into scaffold so add an appBar and inside the AppBar add title text as I am Rich. 

Your code will look something like this:

[void main() {
  runApp(
    MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('I am rich'),
        ),
      ),
    ),
  );
}]

You have successfully added a title to your app. Now we will add our first image into our app. Let us add the body to the scaffold. After the appBar is over, add a body and create a container to it. Now add a child center widget to container and inside the center widget, add one more child, an image widget. This image will be taken from the network so you can select any image to show in your app.

For image, add an image attribute with NetworkImage and add a URL inside the parenthesis. The URL you will enter should be the URL of the image. Here is an image of a diamond for you to use. Open this image in a new tab and you will get the link to this image.
Flutter tutorial: Working with images in Flutter

Your code will look something like this:

[void main() {
  runApp(
  MaterialApp(
     home: Scaffold(
        appBar: AppBar(
          title: Text('I am rich'),
        ),
        body : Container(
          child : Center(
            child: Image(
              image: NetworkImage('https://4cs.gia.edu/wp-content/uploads/2017/05/NewHero_LooseDiamond_700x394.jpg'),
            ),
          )
        ),
     ),
  ),
  );
}]

Now compile the app and you will have an image inside your app. You have successfully added a network image to the app. One thing which you need to do is add a background color. The app looks dull in plain white. So to make our app look more classy, we will add the background color to both the title bar and background of the app.

At the end of the body, add backgroundColor attribute and select the color you want. Do the same after the title bar.

Here is how your code will look after that:

[void main() { runApp( MaterialApp( home: Scaffold( appBar: AppBar( title: Text('I am rich'), backgroundColor: Colors.orange[200], ), body : Container( child : Center( child: Image( image: NetworkImage('https://4cs.gia.edu/wp-content/uploads/2017/05/NewHero_LooseDiamond_700x394.jpg'), ), ) ), backgroundColor: Colors.orange[500], ), ), ); }]

Now the last thing remaining is adding an image asset in the app. Download the diamond image above and paste it into a separate folder named images into the root of your app. So your image address should look like this: /yourprojectfolder/images/yourimage.jpg

Now in your pubspec.yaml file go to code where assets are mentioned and uncomment it. Now click packages get. See to it that there are only two spaces after assets.

Flutter tutorial: Working with images in Flutter

Now you have included the image into your app. Just specify the code where you want to show it. Now instead of NetworkImage add Assetimage and specify the image location which in this case is /images/youimage.jpg.

Here is the code for it:

[void main() {
  runApp(
  MaterialApp(
     home: Scaffold(
        appBar: AppBar(
          title: Text('I am rich'),
          backgroundColor: Colors.orange[200],
        ),
        body : Container(
          child : Center(
            child: Image(
              image : AssetImage('images/daimond.jpg'),
            ),
          )
        ),
       backgroundColor: Colors.orange[500],
     ),
  ),
  );
}]

Flutter tutorial: Working with images in Flutter

Congratulations you have successfully made your first image app. Did you find this tutorial helpful? Comment below to let us know how you feel. Subscribe to our blog for more tutorials on Flutter.

COMMENTS

BLOGGER
Name

Affiliate marketing tutorial,2,Android,60,Android Development,22,Android tutorials,41,Blogging tactics,8,Deals,1,DSA,4,Elite Youtube Tutorial,4,Firebase,1,Flutter,4,Fuchsia,1,Hosting Guides,3,Leetcode,4,Miscellaneous,10,Mobile Gaming,17,NTN,94,Problogging,7,PUBG,16,Reviews,1,SEO Tutorial,5,Start a blog,9,Start a channel,6,Top 5,4,Travel Blogging,4,Windows,12,Windows Security,4,Windows tutorials,7,Wordpress Tutorials,4,Youtube Tutorials,11,
ltr
item
A Passionate Developers Creation: Working with images in Flutter : Complete Flutter Tutorial
Working with images in Flutter : Complete Flutter Tutorial
As I had said in the previous posts, everything is a widget in Flutter, so for working images, we are going to use an image widget. So for understanding the concept of images in detail, we will be making I am Rich app.
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsoDQ7a0ih1_XmsI2KuAOMyHb36-yWKeID7YCY4sgNK8laUYV9bm97OrOZ5wqD9OnAMR-6_mjD-jDw8VkiBhviMLuMNwvZOpTrHlb6aPy6WeMZOFU1RNM_WD8Rq-dW3e5wKCSXkPJvzog/s320/flutter-images.jpg
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsoDQ7a0ih1_XmsI2KuAOMyHb36-yWKeID7YCY4sgNK8laUYV9bm97OrOZ5wqD9OnAMR-6_mjD-jDw8VkiBhviMLuMNwvZOpTrHlb6aPy6WeMZOFU1RNM_WD8Rq-dW3e5wKCSXkPJvzog/s72-c/flutter-images.jpg
A Passionate Developers Creation
https://www.apdevc.com/2020/02/flutter-tutorial-working-with-images-in.html
https://www.apdevc.com/
https://www.apdevc.com/
https://www.apdevc.com/2020/02/flutter-tutorial-working-with-images-in.html
true
3690156770086819421
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content