'Getting "No file or variants found for asset" found error on my asset

I am getting this attached error when I try and run my app. Any ideas? (Below)

Launching lib\main.dart on SM J200Y in debug mode...
Running Gradle task 'assembleDebug'...
√ Built build\app\outputs\apk\debug\app-debug.apk.
Error detected in pubspec.yaml:
No file or variants found for asset: assets/credentials.json.

I have checked the yaml file and the formatting seems to be fine. I am at a loss as want the issue is. (Also, below)

flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true
  # To add assets to your application, add an assets section, like this:
  assets:
  - assets/credentials.json


Solution 1:[1]

In my case, the problem was that I was missing slash /.

At first, I have added my icons path as below.

  assets:
      - assets/icons

I solve the issue by adding as slash / to the end of the path as below:

  assets:
      - assets/icons/

Solution 2:[2]

I was facing the same problem, and I had two mistakes:

  1. I created the "images" folder inside the "lib" folder, and it should be outside the lib folder, it should be in the app root folder. enter image description here

  2. It should be three spaces from the starter line as @Darshan said

    -assets/credentials.json // <-- count three spaces from start

    It should appear a grey line, like this

    enter image description here

Solution 3:[3]

there are 2 possibility

  1. Folder/file missing in your project directory
  2. Missing "/" in the end of folder/file name in pubspec.yaml file

Solution 4:[4]

try copying the file manually not using VS-Code or Android studio. don't use drag/drop.

Solution 5:[5]

Sometimes you need to enter filename as such:

flutter:   assets:
    - lib/assets/logo.png

Solution 6:[6]

You need mention as assets: - assets/icons/

in pubspec.yaml

Solution 7:[7]

I was facing the same problem, and I had two mistakes: When I add lib in assets then I solve my problem.

flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  assets:
    - lib/images/background.jpg

Solution 8:[8]

I had this same problem, I was able to fix it by using only the name of directory created in the projects root folder, instead of also including the file i was trying to point to.

assets:
  - images/

is what worked for me instantly, just point to the whole dir and specify the file name in ImageAssets object.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MendelG
Solution 2 Aamir
Solution 3
Solution 4 Malek Tubaisaht
Solution 5 cigien
Solution 6 Navas Koya
Solution 7 Eric Aya
Solution 8 James Livingstone