'Flutter: Unable to load asset Image provider: AssetImage(bundle: null, name: "assets/images/rose.jpg")

I cant Upload image as a background to a stack, i have added the image in assets folder and added it to pubspec.yaml and showing me that error :

Exception caught by image resource service.
The following assertion was thrown resolving an image codec:
Unable to load asset: assets/images/rose.jpg
When the exception was thrown, this was the stack: 
#0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:225:7)
<asynchronous suspension>
#1      AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:668:31)
#2      AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:651:14)
#3      ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:504:13)
...
Image provider: AssetImage(bundle: null, name: "assets/images/rose.jpg")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#dea48(), name: "assets/images/rose.jpg", scale: 1.0)

Code:

  return new Scaffold(
  backgroundColor: Colors.greenAccent,

  body: new Stack(
    children: [
      new Image(
        image: new AssetImage("assets/images/rose.jpg"),
        fit: BoxFit.cover,
      ),
    ],
  ),

);

My Asset folder



Solution 1:[1]

Run flutter clean and run again.

Solution 2:[2]

Your assets folder is in the right place which is in the root of your project folder.

The error is because you're using the image Provider AssetImage instead of Image.asset("assets/images/rose.jpg").

After making changes to your image asset, make sure you save it to automatically retrieve the new image dependency or run $ flutter pub get.

Also check that you've added the image path to the assets subsection in your pubspec.yaml like this:

flutter: 

 assets:
    - assets/images/rose.jpg

Solution 3:[3]

Have you added the asset in your pubspec.yaml file?

assets:
    - assets/images/rose.jpg

Solution 4:[4]

Please check that your pubspec.yaml file is correctly indented as below. Incorrect spacing/indentation may result in the image not being found.

flutter: 
  assets:
    - assets/images/rose.jpg

Solution 5:[5]

on your terminal :

flutter pub get

to refresh pubspec.yaml

Solution 6:[6]

Stop your emulator and Project and Type :flutter clean in terminal and run again

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 Safal Shrestha
Solution 2 Sharon
Solution 3 Nitish Patel
Solution 4 Ernest Brad N.
Solution 5 CrimsonPiiiik
Solution 6 Code47