How to Install HTTP Package in Flutter?
Flutter is Google’s Mobile SDK to build native iOS and Android apps from a single codebase. When building applications with Flutter everything towards Widgets – the blocks with which the flutter apps are built. The User Interface of the app is composed of many simple widgets, each of them handling one particular job. That is the reason why Flutter developers tend to think of their flutter app as a tree of widgets. HTTP Package is a composable, Future-based library for making HTTP requests. This package contains a set of high-level functions and classes that make it easy to consume HTTP resources. It’s multi-platform and supports mobile, desktop, and browser. In this article, we will look at “How to Install HTTP package in Flutter”. To do so follow the below steps. We are going to discuss two methods for doing this task.
Method 1: Simply from the command line of your flutter project
Run this command:
flutter pub add http
This will add a line like this to your package’s pubspec.yaml (and run an implicit dart pub get):
Note: This will add the current version of the package.
Method 2: By adding explicitly to your package’s pubspec.yaml
Just visit the flutter site.
Now copy the package as shown in the above image. Go to the pubspec.yaml in your flutter project. Under the dependencies section below paste.
Run an implicit dart pub get
Now in your Dart code, you can use:
import ‘package: http/http.dart’;