skip to Main Content

My asset images don’t load. But if I try a network image, it loads properly.

Here is the code: const Image(image: AssetImage('images/logo.png')),

The error: EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════ I/flutter ( 6396): The following assertion was thrown resolving an image codec: I/flutter ( 6396): Unable to load asset: "images/logo.png". I/flutter ( 6396): Exception: Asset not found I/flutter ( 6396): I/flutter ( 6396): When the exception was thrown, this was the stack: I/flutter ( 6396): #0 PlatformAssetBundle.loadBuffer (package:flutter/src/services/asset_bundle.dart:369:7) I/flutter ( 6396): <asynchronous suspension> I/flutter ( 6396): #1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:811:18) I/flutter ( 6396): <asynchronous suspension> I/flutter ( 6396): I/flutter ( 6396): Image provider: AssetImage(bundle: null, name: "images/logo.png") I/flutter ( 6396): Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#daa66(), name: "images/logo.png", scale: I/flutter ( 6396): 1.0) I/flutter ( 6396): ══════════════════════════════════════════════════════════════════════════════════════════════

This is my asset folder,

This is my pubspec.yaml file

2

Answers


  1. Your pubspec.yaml is creating path for images like "assets/images/logo.png". And you are passing it only images/logo.png.

    The the actual issue is you created wrong directory.
    Just create assets directory inside your project, and then create another directory name images inside assets directory.
    So you base path will look like assets/images/

    Now you are able to solve this issue.

    To solve this issue you need to add assets to your passing string in AssetImage

    Code:

    const Image(image: AssetImage('assets/images/logo.png')),

    then run flutter pub get command and restart your application.

    Login or Signup to reply.
  2. Your asset folder indentation having issue please align assets with uses-material-design
    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search