I have uploaded the images to asset folder and updated the pubspec.yaml file too. But the images are not displaying and pubspec.yaml file shows an error.
.yaml error
The asset file ‘assets/warning_lights/tpms.jpg’ doesn’t exist.
Try creating the file or fixing the path to the file.
Folder structure and error
(https://i.sstatic.net/rdTNFvkZ.png)
I have reuploaded the images and tried changing the image type too.
3
Answers
Remove the assets files from lib and place it in root folder of the project. means lib and assets folders will be at same level. like this
what you have done wrong in your folder structure is that you have placed the assets folder inside the lib folder.
the assets folder should always be placed outside
hust like in the picture
and you will be good to go
and also instead of including every images in pubsec.yaml you can simply put assets/ or any folder inside if added and you can access it to with the same path you have used in your code
You’re facing this issue because of incorrect paths in the
pubspec.yaml
. You can resolve this issue by following these two solutions:Solution 1:
Add
lib/
before your assets paths. Because you have put the assets under thelib
directory. More ever you if you want to include all the assets ofwarning_lights
directory you can simply do it like this:No need to add a full path to each image.
Solution 2: Recommended
You should move the assets dirctory to root level of the proejct. i.e. The
lib
directory and theassets
directory should be on the same level.Then in your
pubspec.yaml
:The concept is that the flutter searches for the directory paths relative to the
pubspec.yaml
file. So you have to be careful when adding any paths in thepubspec.yaml