22

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!

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
Vaibhav Dhunde
  • 369
  • 1
  • 4
  • 15

22 Answers22

26

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.

Isaac Benitez
  • 261
  • 1
  • 3
  • 2
14

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/

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
  • 11
    Yes, I did clicked 'Packages Get' in Android Studio (Forgot to mention in the question above). But still it was giving the error. But finally when I went through the link provided by you, the doc says that 'you may have to do a full restart of the app to avoid errors like MissingPluginException when using the package.' So I closed the project and reopened which solved the problem. Thanks! :) – Vaibhav Dhunde Aug 13 '18 at 18:45
  • 2
    I did all steps above but it not work. After that, I close the Android Studio + Simulator and reopen, it works well. – Kim Thành Vũ Jul 20 '20 at 07:39
  • Same happened with me. Closing the Android studio and reopening worked. Looks like the IDE problem – Vighnesh Pai Apr 23 '21 at 08:24
5

Solution (For VSCode):

  1. Run flutter packages get in pubspec.yml
  2. Restart VSCode
Aathil Ahamed
  • 460
  • 4
  • 16
iMujtaba8488
  • 241
  • 3
  • 9
3

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**
  1. Save the pubspec.yaml file
  2. go to your terminal and run 'flutter packages get' 4.Close your simulator and rebuild your cradle
  3. Run the main.dart again and it should remove the error.

This is what worked for me, all the best.

  • building the project is what worked for me when nothing else would – martinseal1987 Jan 17 '19 at 13:18
  • I know this is yeearrs late; but I'm curious as to why you wrapped it in '**', when at least now that is unnecessary, and in fact breaks everything. 0.0 – SLWW Feb 03 '23 at 19:55
3

Make sure that english_words is on the base-line with flutter: enter image description here

1

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.

Peter
  • 437
  • 1
  • 4
  • 20
1

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

jorgeM_dev
  • 11
  • 1
1

I used this and it worked for me... without + sign and version in double quote "".. english_words: "^3.1.5"

1

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

0

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.

  1. Run flutter packages get in pubsec.yaml file (if you are using VS Code it will be easier).

  2. Restart your IDE. Check it now, mostly it will work. If not try third step.

  3. 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.

Aathil Ahamed
  • 460
  • 4
  • 16
0

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:)

MartenCatcher
  • 2,713
  • 8
  • 26
  • 39
0

I faced the same issue but I managed to solve it using the steps below:

  1. add the package as an example english_words: ^3.1.0" in 'pubspec.yaml file.
  2. 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.

octobus
  • 1,246
  • 1
  • 14
  • 20
bassam
  • 1
0

For me nothing worked. Things resolved only after

Flutter upgrade

in pubsec.yaml file

Chirag
  • 1,478
  • 16
  • 20
0

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:

  1. Open the test/.packages file on whatever IDE you are using
  2. Locate the package that is not working and go to that directory on your computer.
  3. Delete the whole package. In my case it was the whole english_words package folder.
  4. In the pubspec.lock and .packages file, delete all instances of that package.
  5. run pub get
aldrin ong
  • 53
  • 1
  • 8
0

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.

Ahmad Khan
  • 757
  • 9
  • 22
0

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
0

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

0

All you need to do is to restart IDE(Android studio or VSCode)

Sir Joe
  • 41
  • 2
0

in your pubspec.yaml file, instead of:

english_words: ^4.0.0

try:

english_words: '4.0.0' 

it worked for me

Ahmed Sbai
  • 10,695
  • 9
  • 19
  • 38
0

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
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
0

environment: sdk: '>=2.19.2 <4.0.0'

check the sdk version.it is worked for me:)

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 30 '23 at 19:42
-1
flutter pub add english_words

downloads the package and add it as a dependency in pubspec.yaml Or you can manually add the dependency inside pubspec.yaml like;

dependencies:
  english_words:

and running flutter pub get will resolve the issue

shamnad sherief
  • 552
  • 5
  • 17