Sigmund
Sigmund

Reputation: 788

Flutter Unable to load asset

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

enter image description here

It has correct place in pubspec.yaml

enter image description here

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

Answers (3)

Vicky Salunkhe
Vicky Salunkhe

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

OMi Shah
OMi Shah

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

Soli
Soli

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

Related Questions