im unable to package get the package "english words" in pubspec.yaml - flutter

I'm unable to get the required package English_words.
under dependencies I added English_words: ^3.1.5
screenshot of "pubspec.yaml" file with execution:
Edit: Issue resolved, importing package worked fine. The full code is also given in the flutter docs.

I suspect you are following the tutorial at https://flutter.io/docs/get-started/codelab#step-2-use-an-external-package ... the "+" in front of english_words there is an indicator of a diff. You should add that line, but leave off the +.

I found error in pubspec.yaml file as shown in your screenshot. You need to add english_words: ^3.1.5 to dev_dependencies rather than in dependencies. Actual code snippet will be:
dev_dependencies:
flutter_test:
sdk: flutter
english_words: ^3.1.5
Then click on Package get (shown in Android Studio) option to add above dependency for the project. You can also do the same using command(in project stucture):
flutter packages get

Related

How to resolve Firebase AdMob Integration problem

I am trying to add AdMob ads to my Flutter app. For that, I tried using firebase_admob (^0.9.3+2) plugin but it's not working for me, it stuck at build.apk.
I am getting the output as :
Note: /home/abhishek/dev/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_admob-0.9.3+2/android/src/main/java/io/flutter/plugins/firebaseadmob/AdRequestBuilderFactory.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
My dependency in pubspec.yml are :
dependencies:
flutter:
sdk: flutter
meta: ^1.1.8
platform: ^2.2.1
firebase_core: ^0.4.0+9
firebase_analytics: ^5.0.2
firebase_admob: ^0.9.3+2
Where am I doing wrong?
See if you can remove firebase_core: ^0.4.0+9 then exec flutter clean
Not sure if it is related or not, but I'm having problems adding dependencies:
Error: Could not resolve the package 'google_sign_in' in 'package:google_sign_in/google_sign_in.dart'.
lib/authsvc.dart:7:8: Error: Not found: 'package:google_sign_in/google_sign_in.dart'
import 'package:google_sign_in/google_sign_in.dart';
I'm able to add the dependency in the pubspec.yaml file, run 'pub get' and it says that it downloads fine. No errors are reported in the editor (i.e. it recognizes the new commands and doesn't flag them). However, when I try to compile/build it, I get the above error message. 'Pub get' worked fine until I upgraded to the latest version of Flutter (v. 1.17.3) before I believe I was on (v. 1.17.0).
To fix it, I hardcoded the path in the Dart_Packages.xml file.
(I'm not looking to troubleshoot further, just adding this in case it helps the developers identify the problem). Thanks!

Flutter autocomplete not working in VSCode for packages

I moved my whole flutter project to a new folder, everything runs fine. The autocomplete works on the build in files from flutter, like Container, Column, but when I try using a package, like provider, I need to go on the pub.dev page and copy the import, import it manually, then I have to write "Provider.of(context)" manually. In the old project, I used to write Provider, press TAB, and everything would be auto imported and the VSCode would auto complete everything related to provider, not just bult in files. Whan should I do?
You must make sure that your dependencies for plugins are mentioned under dependencies: section, not under dev_dependencies: section like following:
dependencies:
flutter:
sdk: flutter
cloud_firestore: ^0.13.7
firebase_auth: ^0.16.1
fluttertoast: ^7.0.2
I was getting the same issue and fixed it by changing the flutter channel.
The problem seems to be with the dart that ships with the flutter code.
If you are still facing this issue. Then try to change your channel
flutter channel ...
And then try
flutter upgrade
This will pull the dart version again and hopefully fix the import issue.
Try to restart VS Code, worked for me.

How to import intl library in Flutter?

I am new in Flutter. When I import the library: import 'package:intl/intl.dart'; , it says that the target of URI doesn't exist:package:intl/intl.dart;
When you import any package, example:
import 'package:intl/intl.dart';
You need to also add the package inside the pubspec.yaml file under the dependencies field example:
dependencies:
intl: ^0.15.7
Then from the terminal you can execute the following command:
flutter packages get
or
From Android Studio/IntelliJ:
Click Packages Get in the action ribbon at the top of pubspec.yaml
more info here:
https://flutter.io/using-packages/
Just to double check, you did import intl: ^0.15.7 into pubspec.yaml; triple check that it has four spaces in front of it (no more and no less); and you ran packages get?
Also, put your focus on the tab for main.dart and hit the green arrow to run it. Sometimes you will then see a popup bar at the top of the screen that tells you pubspec.yaml has changed and you need to run it again from that link in order for it to take. (I've seen that in IntelliJ)
Also, if it's showing red lines under publspec.yaml in the project window but everything is working, that's a bug in the analysis. Ignore it but yes, they do know about it and are working on it. It's often there because, for some reason, pubspec.yaml says your assets directory doesn't exist even though you can access the assets without any problem.
Let IDE do this for you :
flutter pub add intl
After running above command, It will resolve the dependency with the latest version available.
OR
Manual Process
1) Add package in pubspec.yaml file under dependencies field :
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
intl: ^0.17.0 // Add this line
2) Execute the following command in terminal :
flutter packages get
3) Import package in your dart file :
import 'package:intl/intl.dart';
if you are facing errors while installing
it coming because of your old version of SDK.
Just fall back to the intl version back by some points in your pubs
intl: ^0.17.0 ---> intl: ^0.16.1 or any other older version like intl: ^0.15.1 etc.
Sometimes its the version of packages which after update not compatible with your old sdk

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

how to add external package to flutter with visual studio code

the doc reference android studio, but I'm using Visual Studio Code, so how do I do this?
"While viewing the pubspec in Android Studio’s editor view, click Packages get upper right."
in pubspec.yaml I added "english_words: ^3.1.0", and I ran 'flutter packages get' from the command palette but it's not working.
make sure you are saving the file before running flutter packages get
I was having error on mine too. This was my initial code
dependencies:
flutter:
sdk: flutter
http: ^0.12.2
and I got this error
"Error on line 25, column 5 of pubspec.yaml: A dependency may only have one source."
so I adjusted my indentation like so
dependencies:
flutter:
sdk: flutter
http: ^0.12.2
And it worked just fined
HOW TO ADD EXTERNAL PACKAGE TO DART AND FLUTTER WITH VISUAL STUDIO CODE
The final solution to this problem is here
you will get the latest version of whatever package you are looking for
Forget going to the pub.dev to search for your packages and copy the dependency
text.
THE SOLUTION IS:
Install the "pubspec assist" by Jeroen Meijer in the extension menu.
Open the pubspec.yaml file in the vs code.
Simply open the Command Palette (by default, Ctrl+Shift+P on Windows, ⌘+Shift+P
on Mac) and search for "Pubspec Assist" and press ENTER.
Then search for the required package with their names. It will automatically add
the dependencies to the pubspec.yaml file. After that save the file using
Ctrl+S.
Get ready to import the package in the main file.