skip to Main Content

I have a problem, in pubspec.yaml I added new images through - assets/images/google.png, and also - assets/images/notifications.png, for some reason, I can use google.png image, but all the others – there is an error Asset not found, it’s very strange, Flutter SDK is the latest version.

Don’t say: "Check the syntax and the number of indents in this file", I checked, there are no errors anywhere, I did everything exactly the same as in the google.png example, it works."

In the screenshot you can see, the pubspec.yaml file, my code where I want to insert the image, and also on the left, the files, and above you can see that the files exist

════════ Exception caught by image resource service ════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset: "assets/images/test.png".
Exception: Asset not found

enter image description here

3

Answers


  1. change this code

    //- assets/images/test.png
    - assets/images/
    

    By specifying the directory path, you can access the files inside the directory.

    finally

    flutter clean
    flutter pub get
    
    Login or Signup to reply.
  2. Look at the below screenshot and compare the indentation (spacing). If you think everything is identical, you’re good to go & if not? Then, make it.

    Now, stop the current program and execute the below-mentioned commands in the project terminal one by one:

    flutter clean
    flutter pub get
    flutter run
    

    View

    Login or Signup to reply.
  3. When path is correct and its not showing the image then just simply close the app and restart the app it’ll work.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search