Reputation: 788
I could find this issue as quite common, but any of the suggestions didn't help me.
I want to simply show an image:
body: new Image.asset('rh.png',width:300,height:100),
You can see it is in the correct folder
It has correct place in pubspec.yaml
But I still get an error:
Unable to load asset: rh.png
I tried a lot of suggestions from github
or stackoverflow
, but none of them helped me; played with spaces and tabs in .yaml
file (doing flutter clean
after each attempt), tried to rename .png
file and put it in the subfolder - no success. Where is the catch?
Upvotes: 0
Views: 3794
Reputation: 11025
Complete image path should be passed for fetching any asset file
in your case using assets/rh.png
would resolve the error
Upvotes: 2
Reputation: 6186
You didn't add assets
with the filename:
Correct way is: new Image.asset('assets/rh.png', width:300, height:100)
Upvotes: 2
Reputation: 87
The problem is with your path to your .png file. It should address properly to the file location.
Correct form would be something like below:
new Image(image: AssetImage('assets/rh.png')),
Upvotes: 1