Adding Images to Flutter Application
Aug 17, 2021
Add assets to your application.
Open your pubspec.yaml file, you will see a section commented out.
Uncomment the colored section
assets:
- images/a_dot_burr.jpeg
- images/a_dot_ham.jpeg
change to
assets:
- assets/
- assets/images/
In the root folder of your application, create an assets folder, inside the assets folder create another folder called images to hold all the images you going to use in the project. Check the highlighted folder for the assets folder.
/// project structure
assets
images
set image as background
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/world.jpg'),
fit: BoxFit.cover,
),
),
Add image from url
Image.network(
url,
height: 200,
),
Example
body: Center(
child: Image.network(
'https://images.unsplash.com/photo-1451187580459-43490279c0fa?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1352&q=80',
height: 200,
),
)