flutter pub: Add, Get, Upgrade
You have chosen the http package so Sprout can fetch the local weather and skip watering outdoor plants on rainy days. Now it has to get into the project. You could edit pubspec.yaml by hand, but the pub commands do it correctly, including the version, in one line.
The rule
addwrites it,getfetches it,upgrademoves it forward.
flutter pub add http # add to dependencies and fetch
flutter pub add dev:mocktail # add to dev_dependencies (tests only)
flutter pub get # fetch exactly what pubspec.lock says
flutter pub outdated # show newer versions available
flutter pub upgrade # move to the newest allowed versions
flutter pub remove http # take it out againAfter flutter pub add http, pubspec.yaml gains a line like this:
dependencies:
flutter:
sdk: flutter
http: ^1.2.0dependenciesship inside the app.dev_dependenciesare only for development, such as testing and linting tools.getreadspubspec.yamlandpubspec.lockand downloads what is needed. If a lock file exists, it keeps the locked versions.upgradeignores the old locked versions, picks the newest ones your constraints allow, and rewrites the lock file.
flutter pub or dart pub? They are the same tool. Use flutter pub inside a Flutter project, because it runs with the Flutter SDK and knows about Flutter packages. Use dart pub for a pure Dart project, such as a command-line script, that does not depend on Flutter.
Then import and use it:
import 'package:http/http.dart' as http;