Flutter: Unable to load asset
In my case, I needed package property as the image was in my library project and I was running the example project.
package: [your parent directory or project name]
eg. My project name is 'flutter_demo'
AssetImage('assets/images/ic_welcome.png', package: 'flutter_demo'),
pubspect.yaml
flutter: assets: - assets/images/
Directory structure:
flutter_demo -- assets -- images -- ic_welcome.png
Please don't use backslashes, if someone tries to compile your project outside windows it's probably going to fail.
Also there's nothing assuring that a future commit will reject backslashes or treat them as escape character sequence. Then your own project won't compile anywhere.
pubspec.yaml
looks for the indentation and it takes 2 spaces and make sure assets are placed 2 spaces after fluter
if you want the folder assets/files/ to be included you need - assets/files/
, not - assets/
neither - assets
neither -assets/files
. Same for icons you'd need - assets/images/icons/
In the pubsec.yaml
file in flutter you need to write the line assets: ...... starting from the same column position where the uses-material-design: true line is starting from.
your pubspect.yaml
file structure should be like this
flutter:uses-material-design: true assets: - images/some_image.png - images/some_icon.png
After all this hit a flutter clean
command