Flutter http package does not exist

HttpDartFlutter

Http Problem Overview


normally the package should be imported like this:

import 'package:http/http.dart' as http;

but now I get this error:

> [dart] Target of URI doesn't exist: 'package:http/http.dart'. > [uri_does_not_exist]

did it somehow changed in the new updates of Flutter? if so, how can I perform a get request now?

Http Solutions


Solution 1 - Http

It is clear way to add http to flutter

  1. Add this to your package's pubspec.yaml file:

> dependencies: > http: ^0.12.0 // latest one might change

  1. Install it You can install packages from the command line:

with pub:

> $ pub get

with Flutter:

> $ flutter packages get

  1. Import it Now in your Dart code, you can use:

> import 'package:http/http.dart';

If you have done these 3 steps restart your code editor

Solution 2 - Http

Did you add it to pubspec?

dependencies:
  flutter:
    sdk: flutter

  http: 0.12.0

Solution 3 - Http

#In Android Studio import like this

  1. Go to pubspec.yaml
  2. Add dependency http: ^0.12.0+2
  3. Click on Packages get at the top

enter image description here

#Few important things: ###1) Follow the proper indentation while adding the dependency.

> Correct:

dependencies:
  flutter:
    sdk: flutter
  http: ^0.12.0+2

> Incorrect:

dependencies:
  flutter:
    sdk: flutter
    http: ^0.12.0+2

If you add dependency like this and hit Packages get then,
You will receive the error:

> Error on line 21, column 5 of pubspec.yaml: A dependency may only have one source. sdk: flutter

###2) Finding package and latest dependency.
You can find the latest HTTP package Here
All the Dart packages are published on Pubsite where you can find and see trending packages. enter image description here

Solution 4 - Http

Add:

dependencies:
flutter:
sdk: flutter
http: ^0.12.0

to pubspec.yaml, update Packages.get and Packages.upgrade. If still not working restart the IDE.

Solution 5 - Http

Your code looks fine. However after reading the comments below Andrey's answer, you must also make sure that you run flutter packages get or pub get after adding the http dependency to your pubspec.yaml.

Solution 6 - Http

Add dependencies to pubspec like this.

dependencies:
  http: ^0.12.0

**** update packages get.

**** update dependencies.

Solution 7 - Http

First of all, simply restart your code editor The caret ^ is not mandatory. You could add to your pubspec.yaml

dependencies:
  http: 0.12.0+2

flutter packages get is called automatically when you save the file if you are using VSCode or Android studio.

The problem for me was solved by restarting VSCode.

Solution 8 - Http

Go to pubspec.yaml file . then add

http: any

below dependencies:

  dependencies:
    flutter:
    sdk: flutter

    cupertino_icons: ^0.1.2
    http: any

then click Packages get

Solution 9 - Http

try adding the http dependencies before the flutter dependencies and click Packages get

dependencies:
  http: ^0.12.0
  flutter:
    sdk: flutter

If you put after flutter that will make an error. Hope this helps

Solution 10 - Http

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
  http: ^0.12.0

Solution 11 - Http

The answers here mention the package version. If you don't know the package version, but know the package name (as in your case), simply do:

flutter pub add <package_name>

Which, in your case translates to flutter pub add http.

This always fetches the latest package that you can use with your project.

Solution 12 - Http

Clear the contents from .pub-cache folder located inside your flutter installation directory and then create a blank flutter project in android studio/ VS code and add http dependencies and click on "Packages get".

Notice that "http" package should be generated inside .pub-cache\hosted\pub.dartlang.org folder and then in your current project open pubspec.yaml file and click "Packages get", this trick should now resolve your "http" dependencies.

Note: Make sure your network is not blocking the downloads from Pub site and the current project is closed while adding "http" dependencies in another project.

Solution 13 - Http

After doing all the steps provided by @Bawantha if the issue still persists then try the following steps this worked for me.

  1. Restart your android studio.
  2. Go to flutter Inspector toolbar
  3. Click on refresh widget info button.enter image description here

Note: Make sure you have admin rights to do this.

Solution 14 - Http

All existing answers say to add the http dependency to pubspec.yaml,
however that is no longer required.

I was getting this error for a different reason;
I was getting this error in a library file, which had the line, part of my_library.

To fix it I needed to move the import 'package:http/http.dart' as http; line from my part of my_library file into my main library my_library file.

Hopefully this is helpful to someone else.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnimzzView Question on Stackoverflow
Solution 1 - HttpBawanthaView Answer on Stackoverflow
Solution 2 - HttpAndrey TurkovskyView Answer on Stackoverflow
Solution 3 - HttpRohit SinghView Answer on Stackoverflow
Solution 4 - HttpMohammed RousulView Answer on Stackoverflow
Solution 5 - Httpgi097View Answer on Stackoverflow
Solution 6 - HttpRashiduzzaman KhanView Answer on Stackoverflow
Solution 7 - HttpRaphael PinelView Answer on Stackoverflow
Solution 8 - HttpMaryam AzhdariView Answer on Stackoverflow
Solution 9 - Httpgalo hernandezView Answer on Stackoverflow
Solution 10 - HttpPRIME_EONView Answer on Stackoverflow
Solution 11 - HttpShourya ShikharView Answer on Stackoverflow
Solution 12 - HttpJayView Answer on Stackoverflow
Solution 13 - HttpSwapView Answer on Stackoverflow
Solution 14 - HttpTurkeyView Answer on Stackoverflow