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.
Related
my problem is that I am getting an error message saying:
Error detected in pubspec.yaml: No file or variants found for asset: svg/DriverLogoPlain.svg.
My pubspec.yaml:
flutter:
uses-material-design: true
assets:
- svg/DriverLogoPlain.svg
My path to the svg image:
PathImage
Anybody has some to this problem solution please?
Your path in the code is incorrect. You're using assets/svg/DriverLogoOptimized.svg as the path in your Dart code, when it should be svg/DriverLogoOptimized.svg.
This may just be a copy-paste issue, but YAML is also whitespace sensitive, so you can't have flutter: indented so much.
Flutter also doesn't natively support SVGs so beware.
With more info from OP their folder was at the incorrect level. Your assets folder is one level too low. Move it to the same level as android. Not as a subdirectory.
So I am building a calculator with flutter and after changing some of my code, I have been getting this error whenever I hot restart, I get this error:
======== Exception caught by Flutter framework =====================================================
The following assertion was thrown during a service extension callback for "ext.flutter.inspector.setSelectionById":
Id does not exist.
When the exception was thrown, this was the stack:
#0 WidgetInspectorService.toObject (package:flutter/src/widgets/widget_inspector.dart:1283:7)
#1 WidgetInspectorService.setSelectionById (package:flutter/src/widgets/widget_inspector.dart:1345:25)
#2 WidgetInspectorService._registerServiceExtensionWithArg.<anonymous closure> (package:flutter/src/widgets/widget_inspector.dart:864:35)
#3 WidgetInspectorService._registerServiceExtensionWithArg.<anonymous closure> (package:flutter/src/widgets/widget_inspector.dart:861:17)
#4 BindingBase.registerServiceExtension.<anonymous closure> (package:flutter/src/foundation/binding.dart:597:32)
...
====================================================================================================
I have no clue what the error means and I cant find and answer to it anywhere.
The only thing I can infer is that it is possibly something with the inspector due to
"ext.flutter.inspector.setSelectionById"
but I honestly have no idea. I also believe it might not be to do with my code since it doesn't reference anything in there.
I would extremely appreciate if anyone could at least help me understand the error.
If you need more details, just ask me.
The error was probably due to Flutter Dev Tools being open.
I cannot explain why is this happening? But I solved the problem without restarting the whole app.
My Solution:
I just ran the following command:
flutter pub global activate devtools
It downloaded and compiled the dependencies needed for the devtools and reactivated the devtools.
Thank you !
I got this error when I tried to show a CupertinoTimerPicker inside a SimpleDialog. I solved it by wrapping the CupertinoTimerPicker in a sized box with a defined height and width:
Center(
child: SizedBox(
height: 200,
width: 200,
child: CupertinoTimerPicker(
initialTimerDuration: tempDuration,
onTimerDurationChanged: (value) {
print(value.toString());
tempDuration = value;
},
),
),
),
This seems to be a bug. See this Github issue:
I don't know if it's a Dart-Code, DevTools or Flutter bug...
What helped me:
Stop flutter app on device
Delete .dart_tool and build folders from project tree.
Run fresh flutter app installation on device.
For me, cleaning the project and rebuilding again solved the problem.
Clean Command:
flutter clean
Pub Get Command:
flutter pub get
After restarting the app it failed to build showing an error in app level build.gradle so
commented multidex true at default config // multiDexEnable true
multidex xommenting
2. commented its implementation in the dependencies // implementation 'com.android.support:multidex:1.0.3'
dependency commenting
If you're trying to use DevTools and came up with these outputs in Debug Console, the suggested answers might not do good for you. Simply because some show you "how to avoid" it rather than solving. So, here's my 2 cents about solving this if you want to open up DevTools or Widget Inspector to debug your app.
This bug may have been fixed on newer versions (of devtools?) (or of Dart?) but I couldn't manage to solve it by simply "activating devtools globally". So I had to do some ugly stuff but eventually, I've managed to solve it.
My fixpaghetti steps are as below:
Stop debugging the app
Uninstall the app from device
Delete <project-dir>/build folder
run flutter clean from terminal
run cd android && .\gradlew clean (cd android ; .\gradlew clean if you're on powershell)
run flutter pub global activate devtools
run flutter pub get and wait for IDE to resolve errors (if it automatically does not, restart the IDE)
run the app
and add some prayers along the way. Hope you'll fix it!
I just closed widget inspector. Restarted my app and then oppened widget inspector again, the error is gone.
Before I tryed restarting app without closing widget inspector, then after reading this psot I undertand that the infractor was the inspector s I decided to close and reopen it, and it worked.
You should close your compiler and open it again!!!
(maybe you've changed the ui so much)
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/
I am running my first Flutter project
I created a sample project and I was able to run the app in
simulator
I have edited the file main.dart
main.dart
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(home: Text('Hello World')));
Now I am getting the error :
pubspec.yaml
name: flutter_app
description: A new Flutter application.
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
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:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
The same error occurred for me at first ... but it worked when I did a 'hot restart'
Just compile the project again and it will work. The error occurs because static variables are hard compiled on the executable and are not dynamic. If you hot reload the changes, it will not rebuild the executable (apk), so that's why you need to rebuild the app.
Your code works for me...
Have you tried a hot restart? The shortcut is CTRL+SHIFT+\ or just click the button with the green circle-arrow in the console-window
I'm not sure what that error is, since I can't replicate it. However, this is more like what your app should look like. Give this a shot and see if it works.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Text('Hello World'),
);
}
}
Just delete the build and recompile. It worked for me. Use the following code:
flutter clean
flutter run
Usually, a Full App Restart is required after a heavy logic change, as transforming a StatelessWidget into StatefulWidget. Check André Glatzl answer
In Android Studio use the Flutter Hot Restart
A hot restart will work. But the source of the problem might be as follows.
You've created new project. You've deleted boilerplate code and try to modify without a stateful or stateless widget. Flutter tries to rebuild widgets under build() method. But when you hot reload, flutter might not resolve what you've updated.
Another example of such error is, when we create a new static variable(static String token = "abc";) in one Class (like constants.dart) and try to reference them in another screen (constants.token), flutter failed to resolve such static things when we hotreload. but it work fine when we hotrestart.
One of the reasons this happens is you are running the app for the first time and then you make some changes and reload again. Without reloading, stop the execution, and again run the app from scratch, this error won't come.
I also faced the same situation, I fixed it by running the app again, This issue is caused when you applied a lot of change to your code and pressed the hot reload button.
Restarting the app worked in my case.
Run this command again
'flutter run'
should work
You changed the myApp and created your own MaterialApp so all you have to do is after changing the name into MaterialApp instead of hot restart click the play button. It will work.
Thanks
Just press the red stop button and click the play button again. It will work :)
As other answers mention, you can 'hot reload' or rebuild your app to solve this issue.
But the reason why I got this error, was that I have edited the pubspec.yaml file, when editing the pubspec.yaml file, you should stop and rebuild the entire app.
Navigate to your lib folder where your main.dart file is and run the commands below:
PS C:\Users\mobile_app\lib> flutter clean
PS C:\Users\mobile_app\lib> flutter pub get
PS C:\Users\mobile_app\lib> flutter run
although if you are having null safety issues I would prefer you debug your application first. In my encounters this error is of a result of trying to run a class component outside a the Static Widget with context hence the class is loaded before build time making the application fail to start.
I occurred when I was implementing TextEditingController and there after I created a function which has parameter inside, so when I wrote the addListener for the controller, then below error got occurred,
Unimplemented handling of missing static target flutter
but after removing the argument from the addListener function still the issue persists and which broked my application, even I did the hot reload in my Android Studio.
Solution:
Mostly similar to above said, but little different, I terminated my app, and rerun the app, and which fixed the issue.
Hope this would help manyone.
If you have added Hot Reloading extension then exit and try restarting the HOt Reloading.
It should work.
Check your import.
It should be
import 'package:your_app...' not import 'file://C/path/your_app/
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.