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

5,836

Run flutter clean and run again.

Share:
5,836
Admin
Author by

Admin

Updated on December 27, 2022

Comments

  • Admin
    Admin over 1 year

    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