flutter can not find my images assets, what can I be doing wrong?
I got the error on debugger:
Launching lib/main.dart on XT1097 in debug mode... Built build
As far as I know currently only files directly placed under the registered directory are added to assets.
This should work:
flutter:
uses-material-design: true
assets:
- assets/images/
- assets/images/user/
I had the same error. In my case it was because the emulator of the phone that I am using does not have access to the internet.
Run the application on a physical mobile device and it worked immediately.
Solution connect the emulator to the internet.
In my case I have to correct the alignments between my assets and the uses-material-design lines in pubspec.yaml.
flutter:
uses-material-desgin: true
assets:
- images/3.jpg
In my case, while i was using relative path like that Image.asset('./../images/welcome.png')
, it doesn't work.
But if i use absolute path like that Image.asset('images/welcome.png')
, it works !
Previously I set images paths as following
"assets/images/SU.jpg"
then I had this error so I changed it as following
"images/SU.jpg"
then it worked!!
This is how this resolved for me.
Previously I was using the exact paths to images as suggested
assets:
- assets/logo_linked_in.jpg
- assets/logo_medium.png
- assets/logo_stackoverflow.png
- assets/myself.jpg
- assets/sparta.jpg
- assets/fox.png
Then I tried just the parent directory name, which was just using:
assets:
- assets/
Voila! It worked like a charm!
I hope this helps someone.
P.S. - For newbies like me:
Make sure you have correctly indented the pubspec.yaml
as this is very important for the build.