0

I have given two white spaces for assets and 4 white spaces for the image location but also I am getting the error.

This is my pubspec.yaml

flutter:
  uses-material-design: true

  assets:
    - assets/port.jpeg

I am getting the error

════════ Exception caught by image resource service ════════════════════════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset: assets/port.jpeg

When the exception was thrown, this was the stack: 
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 236:49  throw_
packages/flutter/src/services/asset_bundle.dart 227:55                        load
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50            <fn>
dart-sdk/lib/async/zone.dart 1362:47                                          _rootRunUnary
dart-sdk/lib/async/zone.dart 1265:19                                          runUnary
...
Image provider: AssetImage(bundle: null, name: "assets/port.jpeg")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#5a8a3(), name: "assets/port.jpeg", scale: 1)
════════════════════════════════════════════════════════════════════════════════════════════════════

This is my directory

enter image description here

OMi Shah
  • 5,768
  • 3
  • 25
  • 34
  • Can you show the code where you are using the image? Usually, in pubspec.yaml, under assets, you declare only a folder named "images" (you named it "assets" again) and then in the code you enter the image you want from that folder. – Kostas Mar 25 '21 at 06:14
  • check this https://stackoverflow.com/questions/53659809/fluttererror-unable-to-load-asset – Nirmal Vora Mar 25 '21 at 11:20

3 Answers3

0

Just make a hot restart. If that doesn't fix your problem, uninstall and re-run your app in your emulator and you'll be fine

Gkon
  • 31
  • 4
-1

write your asset as:-

 assets:
   - assets/
Deepak Lohmod
  • 2,072
  • 2
  • 8
  • 18
-1
assets:
    
    - assets/port.jpeg

Also, make sure the extension of the image matches the destination image extension.

OMi Shah
  • 5,768
  • 3
  • 25
  • 34
  • thank your for your response it worked after flutter clean and restart –  Apr 08 '21 at 09:57