Error:The following assertion was thrown resolving an image codec: Unable to load asset

3,164 views
Skip to first unread message

Vishnu Sai

unread,
Jul 6, 2020, 10:03:02 AM7/6/20
to Flutter Development (flutter-dev)
Hi 

i have just started learning flutter, this is my first app and I am getting an error. can anyone please help me to resolve the error.

Thanks in advance 
 



Console Output


The following assertion was thrown resolving an image codec:
Unable to load asset: - images/Screenshot.png

When the exception was thrown, this was the stack: 
#0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
<asynchronous suspension>
#1      AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:664:31)
#2      AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:648:14)
#3      ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:501:13)
...
Image provider: AssetImage(bundle: null, name: "- images/Screenshot.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#3ec89(), name: "- images/Screenshot.png", scale: 1.0)
════════════════════════════════════════════════════════════════════════════════════════════════════

Flutter Doctor : output 


C:\Users\Burn_The_Ships\Desktop\Practice\flutter\bin\flutter.bat doctor --verbose
[√] Flutter (Channel stable, v1.17.5, on Microsoft Windows [Version 10.0.19041.329], locale en-CA)
    • Flutter version 1.17.5 at C:\Users\Burn_The_Ships\Desktop\Practice\flutter
    • Framework revision 8af6b2f038 (6 days ago), 2020-06-30 12:53:55 -0700
    • Engine revision ee76268252
    • Dart version 2.8.4

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
    • Android SDK at C:\Users\Burn_The_Ships\AppData\Local\Android\sdk
    • Platform android-30, build-tools 30.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Android Studio (version 4.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 47.1.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] Connected device (1 available)
    • sdk gphone x86 arm • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)

• No issues found!

MY Pubspec.yaml file 
name: i_am_rich
description: A new Flutter application.
version: 1.0.0+1

environment:
sdk: ">=2.7.0 <3.0.0"

dependencies:
flutter:
sdk: flutter

cupertino_icons: ^0.1.3

dev_dependencies:
flutter_test:
sdk: flutter


flutter:
uses-material-design: true
assets:
- images/Screenshot.png

My main.dart file 
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

//the main unction is the starting point for all our flutter apps
void main() {
runApp(
MaterialApp(
home: Scaffold(
backgroundColor: Colors.blue[600],
bottomNavigationBar: Text('this is the addon for this task'),
appBar: AppBar(
title: Text('I am rich'), backgroundColor: Colors.blueGrey[900]),
body: Center(
child: Image(
image: AssetImage('- images/Screenshot.png'),
),
),
),
),
  );
}

Souvik Dutta

unread,
Jul 6, 2020, 10:06:13 AM7/6/20
to Vishnu Sai, Flutter Development (flutter-dev)
In your pubspec.yaml file under assets keep only images/ that is delete screenshot.png

Souvik flutter dev

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/55bce84e-4275-4d82-9a1d-103820bcd14eo%40googlegroups.com.

Vishnu Sai

unread,
Jul 6, 2020, 10:14:47 AM7/6/20
to Flutter Development (flutter-dev)
I have tried your suggestion, but still, I am getting this error

Performing hot restart...
Syncing files to device sdk gphone x86 arm...
Restarted application in 3,257ms.
I/flutter (17046): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
I/flutter (17046): The following assertion was thrown resolving an image codec:
I/flutter (17046): Unable to load asset: - images/Screenshot.png
I/flutter (17046): 
I/flutter (17046): When the exception was thrown, this was the stack:
I/flutter (17046): #0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
I/flutter (17046): <asynchronous suspension>
I/flutter (17046): #1      AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:664:31)
I/flutter (17046): #2      AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:648:14)
I/flutter (17046): #3      ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:501:13)
I/flutter (17046): #4      ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:359:22)
I/flutter (17046): #5      ImageProvider.resolveStreamForKey (package:flutter/src/painting/image_provider.dart:499:80)
I/flutter (17046): #6      ScrollAwareImageProvider.resolveStreamForKey (package:flutter/src/widgets/scroll_aware_image_provider.dart:106:19)
I/flutter (17046): #7      ImageProvider.resolve.<anonymous closure> (package:flutter/src/painting/image_provider.dart:330:9)
I/flutter (17046): #8      ImageProvider._createErrorHandlerAndKey.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:460:26)
I/flutter (17046): (elided 13 frames from dart:async)
I/flutter (17046): 
I/flutter (17046): Image provider: AssetImage(bundle: null, name: "- images/Screenshot.png")
I/flutter (17046): Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#a0193(), name: "- images/Screenshot.png",
I/flutter (17046):   scale: 1.0)
I/flutter (17046): ════════════════════════════════════════════════════════════════════════════════════════════════════

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

When the exception was thrown, this was the stack: 
#0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
<asynchronous suspension>
#1      AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:664:31)
#2      AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:648:14)
#3      ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:501:13)
...
Image provider: AssetImage(bundle: null, name: "- images/Screenshot.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#a0193(), name: "- images/Screenshot.png", scale: 1.0)
════════════════════════════════════════════════════════════════════════════════════════════════════
To unsubscribe from this group and stop receiving emails from it, send an email to flutt...@googlegroups.com.

Souvik Dutta

unread,
Jul 6, 2020, 10:18:37 AM7/6/20
to Vishnu Sai, Flutter Development (flutter-dev)
Also try removing "-" from the asset image

Souvik flutter dev

To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/6e980598-9fcf-455a-b630-4fa622c16a9bo%40googlegroups.com.

Vishnu Sai

unread,
Jul 6, 2020, 10:31:33 AM7/6/20
to Flutter Development (flutter-dev)
It's working now, thanks for the help.

i have accidentally pressed some commend which turned my AVD into pic shown below,

Screenshot_1594045556.png

can you please help me to fix this, 

Thanks in Advance 

Vishnu




Souvik Dutta

unread,
Jul 6, 2020, 11:12:47 AM7/6/20
to Vishnu Sai, Flutter Development (flutter-dev)
There is a pofilling tab in android studio tap on it and you will understand.

Souvik flutter dev

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
Screenshot_1594045556.png
Reply all
Reply to author
Forward
0 new messages