60

I am very new to Flutter, and stuck at the following error:

package:http/http.dart That library is in a package that is not known.

Maybe you forgot to mention it in your pubspec.yaml file?

Please help in resolving this error.

2
  • 2
    that package is part of flutter and should not show an error if you import it. To help you, you should post your relevant parts of the pubspec.yaml and .dart-File Commented Nov 24, 2018 at 22:37
  • The package is not a part of flutter but it is distributed via pub. Commented Nov 25, 2018 at 0:02

19 Answers 19

103

Go to your pubspec.yaml file , and add the http dependency:

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.2
  http: any

Remember, the indentation must be the same as 'flutter' or 'cupertino_icons'

And don't forget to run this command in your terminal :

flutter packages get
Sign up to request clarification or add additional context in comments.

2 Comments

And don't for get to pub get or flutter packages get after saving.
[stackoverflow.com/questions/61037356/… flutter pub is just an alias to flutter packages
21

I had the same problem. You just have to add latest http dependencies in pubspec.yaml

Here is the full code,

  dependencies:
      flutter:
        sdk: flutter

      http: ^0.12.0+1

      # The following adds the Cupertino Icons font to your application.
      # Use with the CupertinoIcons class for iOS style icons.
      cupertino_icons: ^0.1.2

Don't forget to change verson no. of http To check latest version of http click here

If you are running app directly from command line then you could also do:

with Flutter:

$ flutter packages get

with pub:

$ pub get

Comments

14

I've found that, when in VS Code, you might need to restart the editor to get it to see the new http module that 'pub get' pulled in. You can have your .dart code and pubspec.yaml exactly right but you still get the compiler/lint error.

1 Comment

this worked for me after installing the package using flutter pub add http and imported it like this: import 'package:http/http.dart' as http; i still get compiler error, closed my folder and open it up again in Vs Code, error's gone and editor shows warning for unused import only.
11

You need to import like this:

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

Comments

8

1.Install http package

flutter pub add http

2.check pubspec.yaml file

dependencies: 
  http: ^0.13.4

3.Import in file

import 'package:http/http.dart';

Reference

Comments

5

add below to pubspec.ymel file

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.2
  http: ^0.12.0+1

use flutter pub to find the latest version

call

flutter packages get

Comments

4

just got to pubspec.yaml file and tweak some changes in file

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.2

 http:   

under dependencies section just add http like in code description .

flutter will automatically resolve it and will add updated version of http .

Comments

3

You have to add the http dependency in the pubspec.yaml file as shown below:

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.2
  http: ^0.12.0+2

Please take note of the indentation. After doing the above, run the below command in your terminal:

flutter packages get

As at the time of writing this, the latest http version is 0.12.0+2. You can learn more by visiting this link.

Comments

2

this worked for me:

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.2
  http: any

then:

flutter doctor -v

Finally:

flutter packages get

Comments

2

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

dependencies: http: ^0.12.1

2. install it :

$ flutter pub get

3. Now in your Dart code, you can use:

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

Comments

1

-Just run this below command in your project directory to install http module

flutter pub add http

1 Comment

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

Add below to pubspec.yaml file

  dependencies:
  http: ^0.12.0+1
 

Or Just add http

dependencies:
http:

flutter will automatically used latest version of http .

Then use pub get

Comments

0

version: 1.0.0+1

environment: sdk: ">=2.7.0 <3.0.0"

dependencies: flutter: sdk: flutter

cupertino_icons: ^1.0.0 http: ^0.12.2

dev_dependencies: flutter_test: sdk: flutter

flutter:

uses-material-design: true assets: - images/

try to update the sdk versions and then pub get or flutter pub get to get the packages get install

Comments

0

just add in pubspec.yaml

http: ^0.12.0+2

like as

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

and run in terminal

flutter pub get

finally add in class

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

Comments

0

When I got this issue, I just close the project from Android Studio (File -> Close Project). And then open it again.

That works for me.

Simply just Restart the project.

But Make sure to add the certain dependency to the pubspec.yaml file and do pub get.

Comments

-1

You first find 'dependencies:' in pubspec.yaml then under 'dependencies:' type http: ^0.12.0+2 and then press ctrl + s to run get packages.

sample:

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

Comments

-1

cupertino_icons: ^0.1.2

http: any

Comments

-2

http: have to be align with the other dependencies.

1 Comment

Your answer doesn't seem to help the OP. Please clarify and elaborate.
-2

I had the same issue although I had the latest http package in Pubspec.yaml file. This error was still in there I did these 2 steps and error was resolved.

  1. Remove import 'dart:_http'; if it is there
  2. Add import 'dart:convert';

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.