Reputation: 2162
I'm getting this error while adding images folder assets in pubspec.yaml
Error detected in pubspec.yaml:
No file or variants found for asset: lib/assets/images.
This is how my pubspec.yaml
file looks like
flutter:
uses-material-design: true
assets:
- lib/assets/images
fonts:
- family: Potra
fonts:
- asset: lib/assets/fonts/Potra.ttf
- family: BAHNSCHRIFT
fonts:
- asset: lib/assets/fonts/BAHNSCHRIFT.TTF
I tried to look it up. Most of the people are suggesting to give the right indentation for this problem. But I'm quite sure it is not the case here. I tried the proper indentation method and also all possible variants but in vain.
When I remove below part, code runs fine without any error and respective added font family in pubspec also works fine.
assets:
- lib/assets/images
Why I'm getting error after adding assets part?
This is how my file structure looks like
Upvotes: 4
Views: 6468
Reputation: 1655
I got this exception for a silly mistake I have space in my file name like home_cover. jpg
. So I remove it like home_cover.jpg
Upvotes: 0
Reputation: 1609
Your code doesn't work because you need to add one more slash, so it should be like:
assets:
- lib/assets/images/
Tips: It's kinda bad practice if you put your assets
folder inside your lib
folder. Try to place it outside the lib
folder. And also make sure the indentations are correct.
I hope it will be helpful.
Upvotes: 11
Reputation: 92
You should have your assets folder not inside lib folder but in the main root directory( i.e. out of lib ) and then add assets as :
assets:
# For images
- assets/images
fonts:
- family: FontFamilyName
fonts:
- asset: assets/fonts/the_font_you_want.ttf
And beware of indentation in pubspec.yaml, they also cause errors
Upvotes: -1