Home > OS >  problem in importing images in flutter using image.asset()
problem in importing images in flutter using image.asset()

Time:04-19

constantly getting this error saying

The following assertion was thrown resolving an image codec: Unable to load asset: ../images/mall.png

even though the YAML file is correct. environment: sdk: ">=2.18.0-10.0.dev <3.0.0"

dependencies: flutter: sdk: flutter

cupertino_icons: ^1.0.2

dev_dependencies: flutter_test: sdk: flutter

flutter_lints: ^2.0.0

flutter:

uses-material-design: true

assets: - images/

CodePudding user response:

Your pubspec.yaml should look something like this:

assets:
   - images/mall.png
   - images/example.png

and not

assets:
   - images/

Add the all images you need.

CodePudding user response:

Create a folder named as assets in PROJECT DIRECTORY not in lib or some other folder. Drag and drop your image into assets folder. Now your pubspec.yaml would be like

assets:

  • assets/

CodePudding user response:

I think you have a path that looks like:

/assets/images/mall.png

but your pubspec.yaml is saying it's:

/images/mall.png

and can't find it.

Make sure your filetree is the same as you're telling it is in pubspec.yaml and don't forget to indent correctly.

To be clear:

assets:

  • images/

does NOT mean /assets/images/

it should then be:

assets:

  • assets/images/
  • Related