unload assets in flutter

Viewed 314

I am beginner to Flutter and try to place an image inside one of my widgets but give me below error:

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

When the exception was thrown, this was the stack
#0      PlatformAssetBundle.load 
package:flutter/…/services/asset_bundle.dart:221
<asynchronous suspension>
#1      AssetBundleImageProvider._loadAsync 
package:flutter/…/painting/image_provider.dart:484
#2      AssetBundleImageProvider.load 
package:flutter/…/painting/image_provider.dart:469
#3      ImageProvider.resolve.<anonymous closure>.<anonymous closure>.<anonymous closure> 
package:flutter/…/painting/image_provider.dart:327
...
Image provider: AssetImage(bundle: null, name: "../w.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#767fa(), name: "../w.png", scale: 1.0)

pubspec.yaml:

enter image description here

my folders:

enter image description here

transactionlist.dart

// new Image(image: AssetImage('../../w.png'),width: 300,height: 100,),
Image.asset('../../images/w.png'),

I tried a lot of solutions from StackOverflow but none of them worked for me. using Flutter Clean, Cold Boot android emulator, check a thousand-time YAML file, rename a file, but unfortunately, none of them help me to fix it. I really appreciated it if anyone has idea to fix this.

2 Answers

Identation is important thing for yaml folders as you know as. I checked my pubspec.yaml folder and there is no spaces below the assets in my folder. After the changes in pubspec.yaml start it again.

flutter:
  uses-material-design: true

  assets:
  - images/w.png

You can reach the image using Image.Assets("images/w.png")

Did you run flutter packages get command after adding an asset?

Also, give full asset path (exact same one you wrote in pubspec.yaml) and try again.

Image.asset("images/w.png")

If you still get an error, stop the application and start it again. Don't hot reload.

Related