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): ══════════════════════════════════════════════════════════════════════════════════════════════
2
Answers
Your
pubspec.yaml
is creating path for images like"assets/images/logo.png"
. And you are passing it onlyimages/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 inAssetImage
Code:
const Image(image: AssetImage('assets/images/logo.png'))
,then run
flutter pub get
command and restart your application.Your asset folder indentation having issue please align assets with uses-material-design