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.
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.
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
pub get or flutter packages get after saving.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
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.
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.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';
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
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.
-Just run this below command in your project directory to install http module
flutter pub add http
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
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
http: have to be align with the other dependencies.