Reputation: 104
I am not sure why my images from assets is not working
I looked at these two questions:
-https://stackoverflow.com/questions/64158543/flutter-unable-to-load-image-asset
-https://stackoverflow.com/questions/67552389/unable-to-load-image-asset
this is how I am trying to fetch the image:
Image(
image: AssetImage('assets/logo.png'),
width: 100,
height: 100,
),
here is my pubspec.yaml
assets:
- assets/logo.png
- assets/back.png
I tried following videos on youtube but that didnt work.
any suggestions are welcome
Upvotes: 0
Views: 1758
Reputation: 9
Code in the pubspec.yaml should be correct and run
flutter pub get
and you'll be fine.(It worked for me!)
Upvotes: 1
Reputation: 302
if your images are in images folder of assets folder then declare as below in pubspec.yaml
assets:
- assets/images/
And write code to get image as below
Image(
image: AssetImage('assets/images/logo.png'),
width: 100,
height: 100,
),
Upvotes: 2
Reputation: 14775
Try below code and change your pubspec.yaml
file like-
if your images in images folder
assets:
- assets/images
if your images in assetsfolder
assets:
- assets/
after that run command flutter pub get
and Stop the code and re-run again
Refer assets-and-images
Upvotes: 1