Prachik
Prachik

Reputation: 29

'Unable to load asset error' is caught by 'Image resource service'

The Error:

======= Exception caught by image resource service ================================================ The following assertion was thrown resolving an image codec: Unable to load asset: images/google-logo.png

When the exception was thrown, this was the stack: #0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:227:7) #1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:667:14) Image provider: AssetImage(bundle: null, name: "images/google-logo.png") Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#36c1f(), name: "images/google-logo.png", scale: 1.0)

My 'pubspec.yaml' file:

'''flutter:
     uses-material-design: true
     assets:
        - images/facebook-logo.png
        - images/google-logo.png '''

I am loading the image into the page using the following code: IN 'sign in page.dart' file:

'''CustomRaisedButton(
            child: Image.asset('images/google-logo.png'),
            color: Colors.white,
            onPressed: () {},
          ),'''

Upvotes: 1

Views: 6367

Answers (2)

Harshil Khamar
Harshil Khamar

Reputation: 216

Specify Image path as follows

Image.asset("assets/images/car_android.png")

OR

Image(image: AssetImage("assets/images/car_android.png"))

The problem is flutter can't recognize where your image is exactly stored.

If the problem continues then try to do HOT RESTART this will solve your problem.

If you update pubspec.yaml file then run flutter pub get to update the libraries if your IDE doesn't update it automatically.

Upvotes: 0

Sagar R Anghan
Sagar R Anghan

Reputation: 19

First set your image path in pubspec.yaml file's assets propety, Uncomment it and write path for you image folder like.,

flutter:

[2 whitespaces or 1 tab]assets:
[4 whitespaces or 2 tabs]- assets/images/ #path of your image folder

Do pub get once, and can use the images from given path folder.

If your problem is not resolved yet. I think your assets are not loading, use Following commands in terminal,

flutter clean flutter pub get

Restart or Reinstall the application.

Upvotes: 2

Related Questions