Hello my dear friends
Today we will learn ‘How to use images in flutter?’.
Why do we use images in-app?
sometimes we need to use images to show on our screens for different reasons. To learn this we need to follow a few steps only.
Step no 1: — Create an image folder base on the root directory.
Just create a folder named assets and under the assets folder again create a new folder called images. Then paste your image under the images folder like the above image.
Step no 2:- Now we need to enable access to the entire application.
Open pubspec.yaml file and go to the flutter section, there you can see this commented line => # To add assets to your application, add an assets section, like this:
Below these lines, you will see some more commented lines and these lines are important to use images in-app. Now we need to uncomment that line and set your image path here. the example above image,
Note — Maintain the space like the above image otherwise you will not be able to use it.
FInal Step:- Use this path/image in the code to show in our app.
Image.asset("assets/images/app_logo.jpg",height: 200,width: 200,fit: BoxFit.cover,)
Use a widget called Image.asset, It takes an image path, we need to use the proper image path here. like the above code. It has also other properties (height, width, fit),
Result:-
Thanks for reading my article.