3

I'm following a tutorial in flutter where I had to add an image file to the app, I did it like the example but when I run the app nothing shows.

I tried to change and copy the path but the same result every time. I change the pubspec.file as explained.

This is part of the code:

          Card(
            child: Column(
              children: <Widget>[
                Image.asset('assets/images/download.jpg'),
                Text('Food Paradise')
              ],

This is from the pubspec:

flutter:
  uses-material-design: true
assets:
    - assets/images/download.jpg

This is from the RUN log:

  I/flutter (19491): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE 
╞════════════════════════════════════════════════════
I/flutter (19491): The following assertion was thrown resolving an image 
codec:
I/flutter (19491): Unable to load asset: assets/images/download.jpg
I/flutter (19491): 
I/flutter (19491): When the exception was thrown, this was the stack:
I/flutter (19491): #0      PlatformAssetBundle.load 
(package:flutter/src/services/asset_bundle.dart:221:7)
I/flutter (19491): <asynchronous suspension>
I/flutter (19491): #1      AssetBundleImageProvider._loadAsync 
(package:flutter/src/painting/image_provider.dart:429:44)
I/flutter (19491): <asynchronous suspension>
I/flutter (19491): #2      AssetBundleImageProvider.load 
(package:flutter/src/painting/image_provider.dart:414:14)
I/flutter (19491): #3      ImageProvider.resolve.<anonymous closure>. 
<anonymous closure> 
(package:flutter/src/painting/image_provider.dart:267:86)
I/flutter (19491): #4      ImageCache.putIfAbsent 
(package:flutter/src/painting/image_cache.dart:143:20)
I/flutter (19491): #5      ImageProvider.resolve.<anonymous closure> 
(package:flutter/src/painting/image_provider.dart:267:63)
I/flutter (19491): (elided 8 frames from package dart:async)
I/flutter (19491): 
I/flutter (19491): Image provider: AssetImage(bundle: null, name: 
"assets/images/download.jpg")
I/flutter (19491): Image key: AssetBundleImageKey(bundle: 
PlatformAssetBundle#49af1(), name:
I/flutter (19491): "assets/images/download.jpg", scale: 1.0)

The app is running but no image shows.

4 Answers 4

4

Firstly it looks like the pubspec.yaml file content is not properly indented.

It should be something like

flutter:
  uses-material-design: true

  assets:
    - assets/images/jpgs/test.jpg

Furthermore, check if your file is at the correct path, which is relative to pubspec.yaml.
Lastly, run flutter packages get to update the new file. then run flutter clean then flutter run

Sign up to request clarification or add additional context in comments.

Comments

2

if you think you typed all the code correctly then just Re-Run the Code rather than Hot Reload or Hot Restart. It worked for me.

1 Comment

Right, may be the author should check the reload limitations of flutter as well, because he wanted to use the hot-reload. Keep in mind that only the build path is evaluated in hot-reload.
1

Keep in mind you must include the directories when using the asset. Image.asset("assets/images/apersonreading.jpg"),

Comments

0

The Similar problem is occuring in my code but what I did is created an another folder for Images separated from the assets folder and move all of my Image and then Run this in my pubspec.yaml file

*flutter:
uses-material-design: true

assets: - images/waiting.png*

and in part of my code I use this :

Image.asset('images/waiting.png')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.