Home > Net >  The asset file 'assets/x.jpg' doesn't exist
The asset file 'assets/x.jpg' doesn't exist

Time:11-20

I have seen several videos. I have added images but this time it isn't working. What is the problem here idk. As you can see, in the image everything is fine.

enter image description here

CodePudding user response:

your pubspec.yaml file looks fine, what the actual problem was your assets folder is inside the android folder - which is not fair. Please move the asset folder out of the android folder and paste it directly into your root folder.

So your project structure must be:

flutter_application_2/
  - android
  - ios
  - ...
  - assets/
    - x.jpg
    - y.jpg

Hope you can catch it! Regards :)

CodePudding user response:

The error is due to spacing. There must be two spaces indentation before each assets name. Look at this for more info. The below code shows how to write your assets in pubspec.yaml

flutter:
  uses-material-design: true

  assets:
    - assets/x.jpg
    - assets/y.jpg

CodePudding user response:

the assets folder should be in the root folder not inside the android folder

CodePudding user response:

Place it like this. As assets might contain fonts and other assets too

assets:

  • assets/images/

or

Try flutter clean. And rebuild your project. It'll work.

  • Related