Unable to load asset: - flutter

Here is the error massage:
Unable to load asset: assets/images/waiting.png
When the exception was thrown, this was the stack Image provider:
AssetImage(bundle: null, name: "assets/images/waiting.png") Image key:
AssetBundleImageKey(bundle: PlatformAssetBundle#e3e67(), name:
"assets/images/waiting.png", scale: 1.0)
here is my pubspec.yaml
flutter:
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- assets/images/waiting.png

Make sure that the assets folder is at the level of the lib folder of the project, and start the app again, that is, if you add an image, do not use hot reload, Restart the app the first time you add the image.

Related

flutter unable to load image assets

this how I called image in my app
Image.asset('assets/user.jpg')
this is my pubspec.yaml
assets:
-assets/user.jpg
and I get this error
Exception has occurred. FlutterError (Unable to load asset: assets/user.jpg)
You must consider indentation for assets in pubspec.yaml
assets:
- assets/user.jpg
Your indentation is not correct. It should be like this:
assets:
- assets/user.jpg
Make sure user.jpg is placed in assets folder in your project's
main directory (not inside lib folder)
After doing this, make sure you rebuild your app to see these changes.

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/

Unable to load asset flutter package

I can load image from assets/images directory in flutter application, but when load same image from assets directory in flutter package, i get this error:
Unable to load asset: assets/images/logo.png
Image provider: AssetImage(bundle: null, name: "assets/images/logo.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#d6b54(), name: "assets/images/logo.png", scale: 1.0)
When loading assets from a package, use the package parameter. Alternative, use the full path to the asset which would look something like packages/<package_name>/assets/images/logo.png.
final image = AssetImage(name: "assets/images/logo.png", package: 'package_name');
Also make sure your asset in your package is referenced in the assets in your package's pubspec.yaml.
flutter:
assets:
- assets/images/

Flutter - No file or variants found for asset: lib/assets/images

I'm getting this error while adding images folder assets in pubspec.yaml
Error detected in pubspec.yaml:
No file or variants found for asset: lib/assets/images.
This is how my pubspec.yaml file looks like
flutter:
uses-material-design: true
assets:
- lib/assets/images
fonts:
- family: Potra
fonts:
- asset: lib/assets/fonts/Potra.ttf
- family: BAHNSCHRIFT
fonts:
- asset: lib/assets/fonts/BAHNSCHRIFT.TTF
I tried to look it up. Most of the people are suggesting to give the right indentation for this problem. But I'm quite sure it is not the case here. I tried the proper indentation method and also all possible variants but in vain.
When I remove below part, code runs fine without any error and respective added font family in pubspec also works fine.
assets:
- lib/assets/images
Why I'm getting error after adding assets part?
This is how my file structure looks like
Your code doesn't work because you need to add one more slash, so it should be like:
assets:
- lib/assets/images/
Tips: It's kinda bad practice if you put your assets folder inside your lib folder. Try to place it outside the lib folder. And also make sure the indentations are correct.
I hope it will be helpful.
You should have your assets folder not inside lib folder but in the main root directory( i.e. out of lib ) and then add assets as :
assets:
# For images
- assets/images
fonts:
- family: FontFamilyName
fonts:
- asset: assets/fonts/the_font_you_want.ttf
And beware of indentation in pubspec.yaml, they also cause errors
I got this exception for a silly mistake I have space in my file name like home_cover. jpg. So I remove it like home_cover.jpg

Unable top load asset from Flutter plugin

I am developing a flutter plugin, and when using the plugin I get Unable to load asset error. Do I have to do something special when using a plugin?
I have no problem loading images in the main application.
From pubspec.yaml:
flutter:
# To add assets to your plugin package, add an assets section, like this:
assets:
- icons/
- icons/myimage.png # << Just to show, that this also is not not working
uses-material-design: true
plugin:
...
Also tried:
- moving back and forth with TABs etc.
- renamed the folder to assets
Using the image folder asset:
Image.asset('icons/myimage.png', height: 12.0),
I get this error:
flutter: ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
flutter: The following assertion was thrown resolving an image codec:
flutter: Unable to load asset: icons/myimage.png
To load assets from a non-application package, you need to pass the package parameter to methods that load the asset like
Image.asset('icons/myimage.png', package: 'my_package', height: 12.0),
See also docs.flutter.io/flutter/widgets/Image/Image.asset.html
To be able to use assets from a dependency (plugin or plain Dart package) follow https://flutter.dev/docs/development/ui/assets-and-images#bundling-of-package-assets
In a dependency all files need to be inside lib/ because only these files are available for package users.
The asset path in pubspec.yaml needs to start with packages/package_name/some_folder_inside_lib
flutter
assets:
- packages/my_package/some_folder_inside_lib/my_image.png
Currently there is another limitation, that all asset files need to be listed individually in pubspec.yaml in contrary to assets from the application project where listing the folder is enough.
Upvote and subscribe to https://github.com/flutter/flutter/issues/22944 to get notified about updates.