Heitor Peraza
Heitor Peraza

Reputation: 21

Exception caught by image resource service, The following assertion was thrown resolving an image codec:

I am trying to load an image into a scroll, but every time it does not load the image due to error:

Exception caught by image resource service The following assertion was thrown resolving an image codec:
Unable to load asset: assets/images/jorge.png

When the exception was thrown, this was the stack:

0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)

1      AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:464:44)

2      AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:449:14)
...

Image provider: AssetImage(bundle: null, name: "assets/images/jorge.png")

Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#dd41f(), name: "assets/images/jorge.png", scale: 1.0)

(2) Exception caught by image resource service

 Unable to load asset: assets/images/heitor.png

(3) Exception caught by image resource service

 Unable to load asset: assets/images/john.png

 I/chatty  ( 8763): uid=10206(com.festapp.flutter_app_fest) identical 5 lines
 E/AccessibilityBridge( 8763): VirtualView node must not be the root node.


 flutter clean was used, besides exchanging images

 final User currentUser = User(
  id: 0,
  name: 'Current User',
  imageUrl: 'assets/images/greg.png'
);

//usuários

final User Jorge = User(
  id: 1,
  name: 'Jorge',
   imageUrl: 'assets/images/jorge.png'
);

final User John= User(
   id: 2,
   name: 'John',
   imageUrl: 'assets/images/john.png'
); 

final User Heitor = User(
   id: 3,
   name: 'Heitor',
   imageUrl: 'assets/images/heitor.png'

); final User Gui = User( id: 4, name: 'Gui', imageUrl: 'assets/images/heitor.png' );

and images use in:

return Padding(
              padding: EdgeInsets.all(10.0),
              child: Column(
                children: <Widget>[
                  CircleAvatar(
                    radius: 35.0,
                    backgroundImage: AssetImage(favorites[index].imageUrl),
                  ),
                  SizedBox(
                    height: 6.0,
                  ),
                  Text(favorites[index].name, style: TextStyle(
                    color: Colors.blueGrey,
                    fontSize: 16.0,
                    fontWeight: FontWeight.w600,
                  ),
                  ),
                ],
              ),
            );

Exception caught by image resource service

The following assertion was thrown resolving an image codec:

Unable to load asset: assets/images/jorge.png

When the exception was thrown, this was the stack:

0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)

1      AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:464:44)

2      AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:449:14)
...
 Image provider: AssetImage(bundle: null, name: "assets/images/jorge.png")
 Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#dd41f(), name: "assets/images/jorge.png", scale: 1.0)

(2) Exception caught by image resource service

Unable to load asset: assets/images/heitor.png

(3) Exception caught by image resource service

Unable to load asset: assets/images/john.png

Upvotes: 2

Views: 11053

Answers (3)

Ravindra Pawar
Ravindra Pawar

Reputation: 477

To solve this error, you should check your pubspec.yaml file, either the asset folder is indexed like below or not:

flutter:

[2 whitespaces or 1 tab]assets:                  
[4 whitespaces or 2 tabs]- assets/images/  #index all files inside images folder
[4 whitespaces or 2 tabs]- assets/images/elephant.jpg #index only elephant.jpg

Upvotes: 1

ralphcoder
ralphcoder

Reputation: 41

i also faced the same issue, the solution is to stop the main.dart -by clicking the red button given in taskbar and then restart it. sometime its not able to load the images when you add it as fresh

Upvotes: 4

Pablo Barrera
Pablo Barrera

Reputation: 10953

It seems that these image files aren't in your project:

  • assets/images/jorge.png
  • assets/images/john.png
  • assets/images/heitor.png

Make sure you are doing these things:

  • Add the images in the folder assets/images/
  • Specify the images in pubspec.yaml
  • Execute flutter packages get / tap Packages get from pubspec.yaml / tap Get dependencies from any dart file.
  • Use Image.asset() or AssetImage() to show them.

Upvotes: 2

Related Questions