打开CMD终端,执行如下指令(自动添加pubspec.yaml依赖)
Dart项目:
dart pub add http
Flutter项目:
flutter pub add http
插件卸载
Dart项目:
dart pub remove http
Flutter项目:
flutter pub remove http
执行命令
flutter pub get
2.3 执行网络请求
顶级函数请求
import ‘package:http/http.dart’ as http;
var url = Uri.parse(‘https://example.com/whatsit/create’);
var response = await http.post(url, body: {‘name’: ‘doodle’, ‘color’: ‘blue’});
客户端请求并关闭
var client = http.Client();
try {
var uriResponse = await client.post(Uri.parse(‘https://example.com/whatsit/create’),
body: {‘name’: ‘doodle’, ‘color’: ‘blue’