Flutter: Unable to load asset file 'car.png' - flutter

I have added my asset files in my projects root directory, which contains images, fonts and sounds.
added the assets in pubspec.yml file like this:
flutter:
uses-material-design: true
assets:
- assets/images/
Then I try to add an image through Image.asset like code below:
Scaffold(
appBar: AppBar(
leading: Align(
alignment: Alignment.centerRight,
child: Text(
"Uber",
style: TextStyle(
fontSize: 22.0,
fontWeight: FontWeight.w400
),
)
),
),
body: Column(
children: [
Text(
"riyad",
style: TextStyle(color: Colors.black),
),
Image.asset("car_android.png") <-- this like
],
),
);
but it shows me exception that failed to load asset:
The following assertion was thrown resolving an image codec:
Unable to load asset: car_android.png"
My traceback exception:
════════ Exception caught by image resource service ════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset: car_android.png
When the exception was thrown, this was the stack
#0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:224:7)
<asynchronous suspension>
#1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:672:14)
<asynchronous suspension>
Image provider: AssetImage(bundle: null, name: "car_android.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#243b1(), name: "car_android.png", scale: 1.0)
I tried to run command flutter clean command to clean the cache, then run the app again, but the same problems occurs again, that it fails to load asset.
I am new to flutter please provide descriptory answers and also suggest me some blogs to read

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.

Just to push a little further on Harshil Khamar answer which is correct and valid another consideration.
The assets in pubspec.yaml has to be under flutter if you place another entry in between these then it does not know where the assets folder is. It may sound stupid, but I am sure I am not the only one to have done this.
flutter:
uses-material-design: true
generate: true
flutter_intl:
enabled: true
assets:
- assets/images/<<imagename>>
The flutter_intl gets in the way as assets now thinks they is under flutter_intl and not flutter. If I am the only idiot then okay so be it.
flutter_intl:
enabled: true
flutter:
uses-material-design: true
generate: true
assets:
- assets/images/<<imagename>>
This solves the problem

Two problems can cause this problem:
you should stop your project and run it again without any HOT RELOAD
you should add a full directory of the image -> assets/images/YOUR_IMAGE.png

The problem you are having is because you did not give the full path to your asset in the creation of an Image object.
body: Column(
children: [
Text(
"riyad",
style: TextStyle(color: Colors.black),
),
Image.asset("assets/images/car_android.png") <-- this like
],
),

1.Check indentation. See image attached:
Image url path should be defined like this:
Kill and reload app. This seems essential after multiple checks of 1 and 2.

Image.asset("assets/images/car_android.png")
flutter pub clean
flutter pub get
flutter run

Related

Unable to load asset, when filename has accent

i have a simple SvgPicture.asset("media/cikkcsoport/$cikkcsoportkod.svg") in my code,
and if the $cikkcsoportkod has accented value, flutter cannot load the asset.
It works with unaccented filenames, only the accented ones drop error messages like:
════════ Exception caught by SVG ═══════════════════════════════════════════════
The following assertion was thrown resolving a single-frame picture stream:
Unable to load asset: media/cikkcsoport/AÍ.svg
When the exception was thrown, this was the stack
#0 PlatformAssetBundle.load
package:flutter/…/services/asset_bundle.dart:258
<asynchronous suspension>
#1 AssetBundle.loadString
package:flutter/…/services/asset_bundle.dart:83
<asynchronous suspension>
#2 AssetBundlePictureProvider._loadAsync
package:flutter_svg/src/picture_provider.dart:546
<asynchronous suspension>
Picture provider: ExactAssetPicture(name: "media/cikkcsoport/AÍ.svg", bundle: null, colorFilter: null)
Picture key: AssetBundlePictureKey(bundle: PlatformAssetBundle#17a4a(), name: "media/cikkcsoport/AÍ.svg", colorFilter: null, theme: SvgTheme(currentColor: Color(0xff000000), fontSize: 14.0, xHeight: 7.0))
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by SVG ═══════════════════════════════════════════════
Unable to load asset: media/cikkcsoport/AÓ.svg
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by SVG ═══════════════════════════════════════════════
Unable to load asset: media/cikkcsoport/AÁ.svg
════════════════════════════════════════════════════════════════════════════════
How can I resolve this problem?
Try with the below things.
you have latest version on flutter_svg (https://pub.dev/packages/flutter_svg)
Added asset path in pubspec.yaml
Flutter clean & Flutter Pub get,
I hope this things are solve your issue.
I also created a test project for this issue, but I couldn't reproduce, this problem, because my svg files are renamed differently to the simulator filesystem of my test project.
I couldn't find out, what flutter settings causes the difference in the filename encoding.
Maybe I created my main flutter project from the command line, and the test project from VSCode with the Flutter: New Project function.
I can confirm, it is some argument, making the difference, at creating the flutter project.
I created a new flutter project from VSCode, and copy the relevant files to it.
Now I can open all my svg-s.

Flutter image not displaying: "Unable to load asset"

Instead of seeing my image in my app I'm seeing a red box with an X that says Unable to load asset: images/aboutmaggie.png.
I made a directory assets with a subdirectory images. The directory assets is at the same level as pubspec.yaml.
I put the image into the images directory. When I click on the image in Android Studio the image displays.
In pubspec.yaml I have these lines:
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- assets/images/
I added
class AboutRoute extends StatelessWidget {
const AboutRoute({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Kabbalistic Numerology'),
),
body: ListView(
shrinkWrap: true,
padding: const EdgeInsets.all(8),
children: <Widget>[
RichText(
text: TextSpan(
children: <TextSpan>[
TextSpan(
text: 'About Maggie McPherson',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black,
)),
],
),
textAlign: TextAlign.center,
),
RichText(
text: TextSpan(
children: <TextSpan>[
TextSpan(
text:
"Dr. Leslie Margaret Perrin McPherson...",
style: TextStyle(
color: Colors.black,
)),
],
),
),
Image.asset('images/aboutmaggie.png'), // <--this image doesn't load
]));
}
}
I ran flutter pub get. I ran Tools > Flutter > Flutter Clean. I shut down and restarted Android Studio.
The error message is:
======== Exception caught by image resource service ================================================
The following assertion was thrown resolving an image codec:
Unable to load asset: images/aboutmaggie.png
I tried putting another image into assets/images and calling that but the second image wouldn't load either.
What's wrong with this picture?
there is an error in calling the image,
change this line in your code
Image.asset('images/aboutmaggie.png')
to this line
Image.asset('assets/images/aboutmaggie.png')
I hope this helps, thankyou
Try like this:
Image.asset('assets/images/aboutmaggie.png'),
Try below code hope its helpful to you.
Refer documation here for Adding assets and images
Refer Image Class here
Your folder structure
project directory
- assets
- images
- your_image.png
Your pubspec.yaml file
flutter:
assets:
- assets/images/
Your Widget:
Image.asset(
'assets/images/ln.png',//just change your image to my image
height: 150,
//width: 100,
),
Note - If you adding correct code and details then your problem not resolved then stop(exit) the project/app and relaunch again
Result Screen->
You need to provide complete path of the image.
Replace
Image.asset('images/aboutmaggie.png')
with
Image.asset('assets/images/aboutmaggie.png').
It was cacheing issue. Last night I tried
Image.asset('assets/images/aboutmaggie.png'),
but that didn't work. This morning I started up Android Studio and it asked,
pubspec.yaml has changed. Do you want to run flutter pub get?
Well, that's odd. I'd just started Android Studio. I hadn't changed anything. I changed the path back to 'assets/images/aboutmaggie.png', ran flutter pub get, did a hot restart and the image appeared.
Then I opened pubspec.yaml and changed it to
assets:
- assets/bowlingballs/
I ran flutter clean, flutter pub get, did another hot restart, and the image continued to appear.
I changed the path back to 'images/aboutmaggie.png', ran flutter pub get, did a hot restart and the image was gone.
My conclusion is that if you change this path
Image.asset('assets/images/aboutmaggie.png'),
then run flutter pub get and a hot restart then the change will appear. But if you make changes to pubspec.yaml you won't see changes until some cache is cleared. The problem I had last night was that when I set up pubspec.yaml I had an extra space before assets. That version of pubspec.yaml got cached and subsequent versions of pubspec.yaml were ignored. flutter clean clears the Build cache but pubspec.yaml apparently isn't in the Build cache. pubspec.yaml must be cached somewhere else.
In your terminal, run flutter clean to clear up the cache, then run flutter pub get for flutter to fetch your assets folder afresh
This is what worked for me

Flutter cant to load asset

I cannot load my assets images and icons.
What can be the problem, i cant upgrade flutter version because its throw many errors if its supposed to be answer.
BottomNavigationBarItem(
icon: ImageIcon(
AssetImage("assets/icons/cash-back.png"),
color: Color(0xFF3A5A98),
),
label: 'leagues',
backgroundColor: AppColors.white,
),
error:
════════ Exception caught by image resource service ════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset: assets/icons/cash-back.png
When the exception was thrown, this was the stack
#0 PlatformAssetBundle.load
package:flutter/…/services/asset_bundle.dart:227
<asynchronous suspension>
#1 AssetBundleImageProvider._loadAsync
package:flutter/…/painting/image_provider.dart:673
<asynchronous suspension>
Image provider: AssetImage(bundle: null, name: "assets/icons/cash-back.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#c10e3(), name: "assets/icons/cash-back.png", scale: 1.0)
In your image, look at where you have specified the assets.
flutter:
#some comments
assets:
- assets/
Notice how you have put "assets:" and "flutter:" on the same indentation. In pubspec.yaml, whitespace is important. Make sure that your indentation looks like this:
flutter:
#some comments
assets:
- assets/
The comments can make this mistake easy to miss, so make sure you pay very close attention to your indentation. Each child should be one tab or two spaces further indented than its parent.
To include all assets under a directory, specify the directory name with the / character at the end and save all data in specific directory ( All images in images folder )
assets:
- assets/images/
- assets/videos/
and run pub get
After pub get success you can refer your assets like
Image.asset(
'assets/images/trash.png',
scale: 1.8,
),
include this in your pubspec.yaml file,
flutter:
assets:
- assets/
- assets/icons/
For more check this link: Adding assets and images
Try this in your .yaml file
flutter:
assets:
-android/assests/directory/

The Google Fonts Package in Flutter app is not working

First, I added the google_fonts package to your pubspec dependencies.
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
google_fonts: ^0.2.0
Then
import 'package:google_fonts/google_fonts.dart';
and apply to a Text widget
Text(
'This is Google Fonts',
style: GoogleFonts.lato(fontSize: 40),
),
Text(
'This is Google Fonts',
style: GoogleFonts.adventPro(fontSize: 40),
),
Please check internet connection- your emulator does not have internet connectivity. google fonts need internet connection on device/emulator.
After adding the dependency pubspec.yaml file
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
google_fonts: ^0.2.0
run the command in terminal\cmd console as :
> flutter packages get
this will fetch the dependency into your workspace.
Google Fonts are fetched from the internet in the runtime. So you observe this behaviour
To overcome this, download the font from google font and make it available in the asset folder by following the steps below.
Visit the https://fonts.google.com/ and download the lato font.
At the root directory, create a directory called google_fonts.
Copy-Paste lato.ttf file into the google_fonts folder.
Open the pubspec.yaml file, Under the assets: section add the -google_fonts/
And change the code from
// Online Mode
Text(
'This is hammersmithOne from Google Font'
style: GoogleFonts.lato(),
),
to
// Offline Mode
Text(
'This is hammersmithOne from Google Font',
style: TextStyle(fontFamily: 'lato') // This is loaded from assets
),
For futher reference refer this article.
Refer these stackoverflow answers aswell:
https://stackoverflow.com/a/74949875/13431819
https://stackoverflow.com/a/74950261/13431819
I fixed mine by deleting the emulator and installing a new one. My older emulator was not connecting to the internet for some reason and reinstalling it fixed it for me.
Unless you store the fonts in your assets, you need to define explicitly that runtime fetching is enabled for Google Fonts:
GoogleFonts.config.allowRuntimeFetching = true;

FlutterError: Unable to load asset

This is the folder structure of my app
.idea
.vscode
android
build
fonts
Oxygen-Bold.tff
Oxygen-Light.tff
Oxygen-Regular.tff
images
pizza0.png
pizza1.png
ios
lib
ui
home.dart
main.dart
test
.gitignore
.metadata
.packages
app_widgets.iml
pubspec.lock
pubspec.yaml
README.md
In my pubspec.yaml file, I load the fonts and assets like this
flutter:
uses-material-design: true
assets:
- images/pizza0.png
- images/pizza1.png
fonts:
- family: Oxygen
fonts:
- asset: fonts/Oxygen-Regular.ttf
- asset: fonts/Oxygen-Bold.ttf
weight: 700
- asset: fonts/Oxygen-Light.ttf
weight: 300
I'm not getting any errors for this pubspec.yaml, and running flutter packages get gives an exit code of 0.
In my home.dart I have the following class:
class PizzaImageWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
AssetImage pizzaAsset = AssetImage('images/pizza0.png');
Image image = Image(image: pizzaAsset, width: 400, height: 400);
return Container(
child: image,
);
}
}
Which I use elsewhere, in order to show the image (code omitted):
),
PizzaImageWidget(),
],
The building gives no errors. Flutter Doctor -v doesn't give any errors, neither does Flutter Analyze -v. The .apk seems to build just fine but when the app opens up on my phone I get the following error in asset_bundle.dart:
Exception has occurred. FlutterError (Unable to load asset:
images/pizza0.png)
The error is thrown by this class in the asset_bundle.dart file:
/// An [AssetBundle] that loads resources using platform messages.
class PlatformAssetBundle extends CachingAssetBundle {
#override
Future<ByteData> load(String key) async {
final Uint8List encoded = utf8.encoder.convert(Uri(path: Uri.encodeFull(key)).path);
final ByteData asset =
await BinaryMessages.send('flutter/assets', encoded.buffer.asByteData());
if (asset == null)
throw FlutterError('Unable to load asset: $key');
return asset;
}
}
This happens both for the pizza0.png file as well as the pizza1.png file. The files are visible in the tree structure, both in Windows Explorer as in VS Code. The font assets load without issue.
This is the output I am getting when running Flutter Run -v:
[+1068 ms] I/flutter ( 6489): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE
SERVICE ╞════════════════════════════════════════════════════ [ +9
ms] I/flutter ( 6489): The following assertion was thrown resolving an
image codec: [ +2 ms] I/flutter ( 6489): Unable to load asset:
images/pizza0.png [ +2 ms] I/flutter ( 6489): [ +1 ms] I/flutter (
6489): When the exception was thrown, this was the stack: [ +2 ms]
I/flutter ( 6489): #0 PlatformAssetBundle.load
(package:flutter/src/services/asset_bundle.dart:221:7) [ +1 ms]
I/flutter ( 6489): [ +1 ms] I/flutter (
6489): #1 AssetBundleImageProvider._loadAsync
(package:flutter/src/painting/image_provider.dart:429:44) [ +1 ms]
I/flutter ( 6489): [ +1 ms] I/flutter (
6489): #2 AssetBundleImageProvider.load
(package:flutter/src/painting/image_provider.dart:414:14) [ +1 ms]
I/flutter ( 6489): #3 ImageProvider.resolve..
(package:flutter/src/painting/image_provider.dart:267:86) [ +4 ms]
I/flutter ( 6489): #4 ImageCache.putIfAbsent
(package:flutter/src/painting/image_cache.dart:143:20) [ +3 ms]
I/flutter ( 6489): #5 ImageProvider.resolve.
(package:flutter/src/painting/image_provider.dart:267:63) [ +3 ms]
I/flutter ( 6489): (elided 8 frames from package dart:async) [ +1
ms] I/flutter ( 6489): [ +1 ms] I/flutter ( 6489): Image provider:
AssetImage(bundle: null, name: "images/pizza0.png") [ +3 ms]
I/flutter ( 6489): Image key: AssetBundleImageKey(bundle:
PlatformAssetBundle#20fc8(), name: "images/pizza0.png", [ +1 ms]
I/flutter ( 6489): scale: 1.0) [ +2 ms] I/flutter ( 6489):
════════════════════════════════════════════════════════════════════════════════════════════════════
You should consider the indentation for assets
flutter:
assets:
- images/pizza1.png
- images/pizza0.png
More details:
flutter:
[2 whitespaces or 1 tab]assets:
[4 whitespaces or 2 tabs]- images/pizza1.png
[4 whitespaces or 2 tabs]- images/pizza0.png
After all this, you can make a hot-restart.
Running flutter clean solved my issue.
More about this error
The simplest way is to reference your assets folder instead of the asset itself, just make sure you use proper indentations as the pubspec.yaml is indent sensitive.
flutter:
uses-material-design: true
assets:
- images/
and you can simply access each image as
Image.asset('images/pizza1.png', width:300, height:100)
For me,
flutter clean,
Restart the android studio and emulator,
giving full patth in my image
image: AssetImage(
'./lib/graphics/logo2.png'
),
width: 200,
height: 200,
);
these three steps did the trick.
Encountered the same issue with a slightly different code. In my case, I was using a "assets" folder subdivided into sub-folders for assets (sprites, audio, UI).
My code was simply at first in pubspec.yaml- alternative would be to detail every single file.
flutter:
assets:
- assets
Indentation and flutter clean was not enough to fix it. The files in the sub-folders were not loading by flutter. It seems like flutter needs to be "taken by the hand" and not looking at sub-folders without explicitly asking it to look at them. This worked for me:
flutter:
assets:
- assets/sprites/
- assets/audio/
- assets/UI/
So I had to detail each folder and each sub-folder that contains assets (mp3, jpg, etc). Doing so made the app work and saved me tons of time as the only solution detailed above would require me to manually list 30+ assets while the code here is just a few lines and easier to maintain.
I also had this problem. I think there is a bug in the way Flutter caches images. My guess is that when you first attempted to load pizza0.png, it wasn't available, and Flutter has cached this failed result. Then, even after adding the correct image, Flutter still assumes it isn't available.
This is all guess-work, based on the fact that I had the same problem, and calling this once on app start fixed the problem for me:
imageCache.clear();
This clears the image cache, meaning that Flutter will then attempt to load the images fresh rather than search the cache.
PS I've also found that you need to call this whenever you change any existing images, for the same reason - Flutter will load the old cached version. The alternative is to rename the image.
inside pubspec.yaml, DON'T USE TAB!
flutter:
<space><space>assets:
<space><space><space><space>assets/
example:
flutter:
assets:
assets/
Some times cache will create a problem so first run
flutter clean
after this run
flutter pub get
Actually the problem is in pubspec.yaml,
I put all images to assets/images/ and
This wrong way
flutter:
uses-material-design: true
assets:
- images/
Correct
flutter:
uses-material-design: true
assets:
- assets/images/
i just Re-run My app instead of just hot Reload.
if you're developing flutter packages, please add package param after image path like this:
AssetImage('images/heart.png', package: 'my_icons') // my_icons is your plugin name, in flutter plugin is also a package.
Here is the link from flutter docs
https://flutter.dev/assets-and-images/#from-packages
I haved a similar problem, I fixed here:
uses-material-design: true
assets:
- assets/images/
After, do:
Flutter Clean
In my case a restart didn't help.
I had to uninstall the app and then run everything again.
It did worked!
After you did all things and still not working, try:
flutter clean
flutter pub get
sometimes after updating pubspec.yaml file, it can not run pub get although it shows it is running.
try commands above
you should start image path with assets word:
image: AssetImage('assets/images/pizza0.png')
you must add each sub folder in a new line in pubspec.yaml
The only thing that worked for me to mention THE WHOLE PATH in the CODE. That is you must mention the image path from the root directory on the code page, in YAML it works with the top-level directory.
You probably can't get away only with the main directory path in code, I have tried a lot and that's the only thing that works.
hope it solved the issue and saved your time.
The 1st image is of code and the second is of the yaml.
There is clearly some sort of flutter bug. This is my directory structure:
<project>/assets/images/myimage.png
This is what I have in pubspec.yaml:
flutter:
uses-material-design: true
assets:
- assets/images/
And this is how it used to work and still works when I compile for web:
const DecorationImage(image: AssetImage("images/myimage.png")
But it will only work when I compile for ios like this:
const DecorationImage(image: AssetImage("assets/images/myimage.png")
Luckily adding "assets/" as a prefix works now in all cases.
While I was loading a new image in my asset folder, I just encountered the problem every time.
I run flutter clean & then restarted the Android Studio. Seems like flutter packages caches the asset folder and there is no mechanism to update the cache when a developer adds a new image in the project (Personal thoughts).
Make a habit to check pubspec.yaml when you are struggling to load an image in a Flutter project. Most of the time, the problem is with it.
The correct way is mentioned below. Do not use the Tab key to keep the spaces. Instead, use the Space bar.
flutter:
uses-material-design: tru
assets:
- images/image1.jpg
And make sure you include the same correct path in your dart file.
One trick I always use is renaming the image with a very short name to avoid typo errors.
Hope this would be helpful to anyone who faces these kinds of problems.
If everything is ok, correct path, correct pubspec spaces, etc, the last thing that could cause this is cache. You can close the simulator and start your application again, it helps for my case.
This is issue has almost driven me nut in the past. To buttress what others have said, after making sure that all the indentations on the yaml file has been corrected and the problem persist, run a 'flutter clean' command at the terminal in Android studio. As at flutter 1.9, this should fix the issue.
Another cause of similar problem:
On Windows you should not use \ sign as directory separator. So
instead of
AssetImage('images\heart.png')
use
AssetImage('images/heart.png')
It can be a bug of Windows version of Flutter. It solved my problem.
One more answer in the mix:
My pubspec.yaml looked like this:
flutter:
assets:
- assets/us_defs/
- assets/eu_defs/
- assets/images/
and in the invoking code:
Center(
child: Image(
image: AssetImage('assets/images/<name.png>')
)
)
(The *_defs folders contain json files for various other purposes and I can load them just fine.)
But, the image wouldn't load, no matter what I tried. Checked and double checked the indent spacing, spelling, invoked flutter clean and flutter pub get, cold started the app, etc. Tried referencing 'images/<name.png>' vs 'assets/images/<name.png>'.
Nada.
Finally, I lifted the images folder to the top level under the project folder:
flutter:
assets:
- assets/us_defs/
- assets/eu_defs/
- images/ <-- now a top level folder
and in the invoking code:
Center(
child: Image(
image: AssetImage('images/<name.png>');
)
)
... and that worked.
I have no idea why.
Now, I'd rather keep the images folder in assets since it fits my sensibilities, but if this reorg gets me going, I'll live with it.
I had the same issue I corrected it, you just need to put the two(uses-material-design: true and assets) in the same column and click in the upgrade dependencies but before restart android studio.
Make sure the file names do not contain special characters such as ñ for example
Dec 25th, 2019 :
Whoever facing issue regarding Image not showing in Flutter , let me give you simple checkpoints :
Image.asset('assets/images/photo1.png'); -- here make sure dont use / (forward slash ) before assets.
YAML file always be clear dont use space , instead use TAB.
YAML file add entries for assets. as mentioned in above comment.
First point is very important
This issue still existed in my case even after,
flutter clean (deletes build folder) and proper indentations in yaml file
It got fixed by itself, as it could be an issue related to Android Studio.
Fix 1) Restart the emulator in Cold Boot mode, In Android Studio,
after clicking List Virtual Devices button, click Drop down arrow (last icon next to edit icon)
=> Choose Cold Boot Now option. If issue still exist, follow as below
Fix 2) After changing the emulator virtual device as a workaround,
For Example : From Nexus 6 to Pixel emulator
--happy coding!
After declaring correctly in pubspec.yaml, consider giving full path of the image ex.
'assets/images/about_us.png'
instead of just images/..
worked for me after wasting 2 hours on such a trivial error.
I was also facing the same issue . The issue on my side was that the image name was having the space in between its name so I updated the image name with the new name that does not have any space.
Image name creating the error was comboclr emtpy no circle.png
I updated this name to comboclr_emtpy_no_circle.png
I ran into this issue and very nearly gave up on Flutter until I stumbled upon the cause. In my case what I was doing was along the following lines
static Future<String> resourceText(String resName) async
{
try
{
ZLibCodec zlc = new ZLibCodec(gzip:false,raw:true,level:9);
var data= await rootBundle.load('assets/path/to/$resName');
String result = new
String.fromCharCodes(zlc.decode(puzzleData.buffer.asUint8List()));
return puzzle;
} catch(e)
{
debugPrint('Resource Error $resName $e');
return '';
}
}
static Future<String> fallBackText(String textName) async
{
if (testCondtion) return 'Some Required Text';
else return resourceText('default');
}
where Some Required Text was a text string sent back if the testCondition was being met. Failing that I was trying to pick up default text from the app resources and send that back instead. My mistake was in the line return resourceText('default');. After changing it to read return await resourceText('default') things worked just as expected.
This issue arises from the fact that rootBundle.load operates asynchronously. In order to return its results correctly we need to await their availability which I had failed to do. It strikes me as slightly surprising that neither the Flutter VSCode plugin nor the Flutter build process flag up this as an error. While there may well be other reasons why rootBundle.load fails this answer will, hopefully, help others who are running into mysterious asset load failures in Flutter.