Flutter: Unimplemented handling of missing static target - flutter

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/

Related

Flutter - different asset path in package's example when building

When creating a custom package that contains font as a .ttf file. I try to download the font file also in the example app that is contained in the package.
The font is downloaded successfully on iOS and macOS apps but not on Linux or Web.
The web console is giving me an error
Failed to load font My-Custom-Icons at assets/../lib/assets/fonts/My-Custom-Icons.ttf
...
my_package:
# When depending on this package from a real application you should use:
# custom_package: ^x.y.z
# See https://dart.dev/tools/pub/dependencies#version-constraints
# The example app is bundled with the plugin so we use a path dependency on
# the parent directory to use the current plugin's version.
path: ../
...
flutter:
uses-material-design: true
fonts:
- family: My-Custom-Icons
fonts:
- asset: ../lib/assets/fonts/My-Custom-Icons.ttf
I would expect that font would be downloaded the same way on all different platforms. What I'm missing here?
Hi just replace this and try.
- asset: assets/fonts/My-Custom-Icons.ttf
Ah, it seems that you can use the packages path when importing the font even inside the example. So the following did the work.
...
my_package:
# When depending on this package from a real application you should use:
# custom_package: ^x.y.z
# See https://dart.dev/tools/pub/dependencies#version-constraints
# The example app is bundled with the plugin so we use a path dependency on
# the parent directory to use the current plugin's version.
path: ../
...
flutter:
uses-material-design: true
fonts:
- family: My-Custom-Icons
fonts:
- asset: packages/my_package/assets/fonts/My-Custom-Icons.ttf

packages get not fetching .packages for English Words with proper pubspec.yaml

for context I am currently following this exercise provided by flutter dev: https://codelabs.developers.google.com/codelabs/first-flutter-app-pt1/#3
I use android studio on a Windows 10 profesional.
I have seen this issue across many different areas and I am continually unable to get the English_Words package to upload. I had even uploaded the file directly the .packages and had the import work, however, the functions and classes do not validate
This is the import from main.dart
This is the pubspec.yaml, with the dependency properly spelled out
I had navigated and manually put in the english_words dependency. However, then the methods would not engage, even when the import worked. Furthermore, when I did ''' -flutter packages get ''', the file was removed, even with the .yaml dependency spelled out.
I have done lots of the recommended things:
-flutter doctor
-deleting the pubspec.lock and upgrading/getting packages
-shutting down the virtualization and android studio
cupertino icon and english words must have have a spacing of 2 just like flutter
ex:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
english_words:^3.1.5
this is a YAML file so spacing have a special meaning. just correct it as i did in example enjoy.

error in importing Http/http.dart package

I updated the dependencies with proper indentation, then flutter pub get and then import it in the code. Tried to restart my ide as well. The error pops up when i try to build the application.
Error:
Unable to find modules for some sources, this is usually the result of
either a bad import, a missing dependency in a package (or possibly a
dev_dependency needs to move to a real dependency), or a build failure
(if importing a generated file).
Please check the following imports:
import 'package:http/http.dart' as http; from myapp|lib/myapp.dart
at 83:1
Code:
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'dart:async';
void main(){
runApp(MaterialApp(
home: HomePage(),
));
}
class HomePage extends StatefulWidget {
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
Future getData() async{
http.Response response = await http.get("http://dummy.restapiexample.com/api/v1/employees");
debugPrint(response.body);
}
#override
void initState() {
super.initState();
getData();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Employees"),
backgroundColor: Colors.green,
),
);
}
}
pubspec.yaml
name: myapp
description: A new Flutter project.
# 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
http: ^0.12.0+4
# 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: IndieFlower
fonts:
- asset: fonts/IndieFlower-Regular.ttf
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
Have you tried restarting your IDE?
https://flutter.dev/docs/development/packages-and-plugins/using-packages
Stop and restart the app, if necessary If the package brings
platform-specific code (Java/Kotlin for Android, Swift/Objective-C for
iOS), that code must be built into your app. Hot reload and hot
restart only update the Dart code, so a full restart of the app might
be required to avoid errors like MissingPluginException when using the
package.
I see your Flutter version is 1.13.6.
I also experienced some strange problems with this version, but when I switched to dev channel all the problems are gone.
Try this too:
flutter channel dev
flutter upgrade
do not use vscode run&debug feature , use this command to run flutter run -d web-server --web-hostname= --web-port= --profile -v ,replace "ipaddress" and "freeport" with your system input

Target of URI doesn't exist 'package:english_words/english_words.dart'

I'm learning to use Flutter using Android Studio. I'm going through step by step doc provided by Flutter. At Step:2 Use an external package I'm getting issue importing the english_words package. I have properly added the package in pubspec.yaml and clicked Packages Get which added the dependency but at the time of importing the package in lib/main.dart it is saying
Target of URI doesn't exist
'package:english_words/english_words.dart'.
I have seen many questions on StackOverflow but none of them helped me. Please help!
For some packages, once you do all the process described by the other answers to this question, you have to close the Android project and open it again. As well as the emulator.
Some packages need the restart, others do not need it.
After adding the package in the pubspec.yaml file, you need to execute the command flutter packages get or click on "Packages Get" in the action ribbon at the top of pubspec.yaml file.
Then the dependency and any transitive dependency will be added to the .packages file.
Check this:
https://flutter.io/using-packages/
Solution (For VSCode):
Run flutter packages get in pubspec.yml
Restart VSCode
I had the same issue and went about it like listed below and it worked.
1. Add the package
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
**english_words: ^3.1.5**
Save the pubspec.yaml file
go to your terminal and run 'flutter packages get'
4.Close your simulator and rebuild your cradle
Run the main.dart again and it should remove the error.
This is what worked for me, all the best.
Make sure that english_words is on the base-line with flutter:
Took me a lot of time, but in summary, just save the file pubspec.yaml will do. The command flutter pub get will be ran once u save it, then u can import the package.
There is no need to restart ur editor etc.
My solution was to add the "english_words: ^3.1.5" the version at the moment that I write this, under the "dependencies:" and before the "Flutter:" argument, without the "+" sign.
Hope that helps
I used this and it worked for me... without + sign and version in double quote ""..
english_words: "^3.1.5"
Make Sure that the alignment of english_words is correct inside your pubspec.yaml as it's "space sensitive" :
dependencies:
english_words: ^3.1.5 //two spaces
also never align it using tabs, I don't know why but it never works, and don't use + sign
There are so many methods to solve this issue, most of them will get solved on the second step,if not please try third method also it will work.
Run flutter packages get in pubsec.yaml file (if you are using VS Code it will be easier).
Restart your IDE.
Check it now, mostly it will work. If not try third step.
you have to repair pub caches
flutter packages pub cache repair
I hope it will work. if all methods are not working try to re install flutter.
my friend solution is so simple only add this code line in file pubspec.yaml
english_words: ^3.1.0
like this
dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
english_words: ^3.1.0
dev_dependencies:
flutter_test:
sdk: flutter
it would work perfectly:)
I faced the same issue but I managed to solve it using the steps below:
add the package as an example english_words: ^3.1.0" in 'pubspec.yaml file.
save file or press ctrl+s
//the Output Console will appear this message
[app name] flutter packages get.
Running "flutter pub get" in first_app..., 2.4s
exit code 0.).
3. check main.dart file, the error will be removed.
For me nothing worked. Things resolved only after
Flutter upgrade
in pubsec.yaml file
For those who are still experiencing this problem, it took me hours to figure out what was wrong. Basically, if all the other answers don't work:
Open the test/.packages file on whatever IDE you are using
Locate the package that is not working and go to that directory on your computer.
Delete the whole package. In my case it was the whole english_words package folder.
In the pubspec.lock and .packages file, delete all instances of that package.
run pub get
In the docs of https://flutter.dev/docs/get-started/codelab there is the following code:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.3
+ english_words: ^3.1.5
The thing which is causing the error is "+ sign". I just removed it and all worked fine for me.
Delete the plus sign "+" in front of english_words (if you have one)
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
english_words: ^3.1.5
I got the same issue.
It is observed only in version 4.0.0 .For lower versions there is no problem.
So here is what you can do to solve this:
Download code for the dependency from :
https://github.com/filiph/english_words
Unzip it Rename it to
english_words-4.0.0
Copy this folder.
Now go to flutter's SDK folder and navigate to
.pub-cache\hosted\pub.dartlang.org
and paste the folder english_words-4.0.0 here. Add dependency in pubspec.yaml file. Now run flutter pub get command.
You are good to go.
Note : How to find the path of Flutter SDK
All you need to do is to restart IDE(Android studio or VSCode)
Having this error message:
Error: Cannot run with sound null safety, because the following
dependencies don't support null safety:
package:english_words
I had to change this dependency english_words: ^3.1.5 to the latest version english_words: ^4.0.0 and make "pub get":
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
english_words: ^4.0.0
provider: ^6.0.0
in your pubspec.yaml file, instead of:
english_words: ^4.0.0
try:
english_words: '4.0.0'
it worked for me

Flutter - Custom Font not displaying

This is an excerpt of my pubspec.yaml file:
flutter:
uses-material-design: true
fonts:
- family: Coiny
fonts:
- asset: fonts/Coiny-Regular.ttf
I am trying to use the font called "Coiny" from the Google Fonts page. I created a fonts folder inside my root directory and put it in there.
In my code, I do this:
new Text("Testtext", style: new TextStyle(fontFamily: "Coiny")),
But it has no effect. I have encountered a similar problem in the past with the Barrio font. But it seemed to work after some time, which is not the case with this one.
You might want to try removing the app from the device and reinstalling it. Depending on how you're launching, it might not be writing over the old install file.
I had font: not right under flutter:. I moved the font: section right under flutter: , and worked.
flutter:
fonts:
- family: Test
fonts:
- asset: assets/fonts/Font-Test.ttf
I had the same issue. If you're testing via an emulator, you just need to stop and restart it. Via VSCode you can just stop the run process (Red square in the top right) and then run -> Run without debugging or Start Debugging
Whenever you make changes to pubspec.yaml file, it is always a good idea to stop the ongoing dart process from your IDE and do a full restart.
If you do hot reload or hot restart, engine may not be able to fetch the newly added data to your file. If nothing works, you should use #Collin answer, uninstall and reinstall the app.
Font declaration alignment is not as per flutter pubspec.yaml. It should be like below.
fonts:
- family: Coiny
fonts:
- asset: fonts/Coiny-Regular.ttf
You can check out it here.
Just Uninstall previous flutter app apk from your android device and again run application. This will resolve your problem. If this not working then clear device cache and try again.
You have add new files in the app therefore you have to
close the running device and then restart the emulator.
-stop a running emulator
-run a emulator
It works in my case.
I had an issue with the font and was receiving these two warnings:
Warning: No fonts specified for font [font family name]
Warning: Missing family name for font.
The issue was that I had the pubspec.yaml fonts section typed incorrectly.
Make sure your pubspec.yaml looks like this:
flutter:
fonts:
- family: FontFamily
fonts:
- asset: fonts/Font-Medium.ttf
uses-material-design: true
You will then need to flutter clean and then flutter pub get. If all of this fails, try to uninstall the app and then reinstall it again (as Collin states above) after doing the above.
I had a "-" next to the nested fonts declaration, which was causing those errors (and the font not to work).
In my case the font asset files were corrupted. Try installing them on your local machine first. If it gives you an error then they are corrupted.
I also encountered this issue, after setting the font B, it not showing correctly.
But the issue for me was I made an empty line between two font-family, like below
fonts:
- family: A
fonts:
- asset: assets/fonts/A-Regular.ttf
- family: B
fonts:
- asset: assets/fonts/B-Regular.ttf
remove the empty line between two font families, This was the working solution for me and remember YAML is INDENTATION sensitive
I tried everything but the changes in pubspec.yaml just did not make any difference. I then created a new project. copied font files to respective folder, made all changes to pubspec.yaml, pasted code into my main.dart file. I ensured everything was in place and then ran project in simulator and viola all fonts appeared in full glory.
I had the other reason. Consider removing spaces from family name. For example, use "MavenPro" instead of "Maven Pro".
Also check you put fonts section into flutter section.
Idek, sometimes I've found you need to totally kill your simulator or device and re-install to get some fonts to work.
I've also found that some font just refuse to work.
Try a different font to to confirm your sanity that your pubspec and TextThemes are actually correct with known working font.
set in pubspec.yaml
fonts:
- family: Montserrat
fonts:
- asset: assets/fonts/Montserrat-Regular.ttf
- asset: assets/fonts/Montserrat-Bold.ttf
and then make sure that clean and build
1. Check the indentation. Every sub-property has 2 spaces from the left. Don't use tab spaces.
2. Stop the dart file execution and try to cold boot the emulator.
3. Try doing a hot restart.
Refer to this YouTube Tutorial.