基于 Http 实现网络操作
什么是 Http 库
Http 库是 Flutter 社区开发的一个可组合的、跨平台的用于 Flutter 的网络请求插件。
如何使用 Http 库
添加依赖
在 pubspec.yaml 中引入 http 插件,进入 http 库后点击 installing http 库地址:https://pub.dev/packages/http
shell
dependencies:
http: <latest_version>引入依赖后,点击 Pub get 获取依赖 
导入http
在dart文件中导入
shell
import 'package:http/http.dart' as http;使用 http 库做 get 请求
shell
///发送Get请求
_doGet() async {
var uri = Uri.parse('https://api.geekailab.com/uapi/test/test?requestPrams=11');
var response = await http.get(uri);
//http请求成功
if (response.statusCode == 200) {
setState(() {
resultShow = response.body;
});
} else {
setState(() {
resultShow = "请求失败:code: ${response.statusCode},body:${response.body}";
});
}
}
剑鸣秋朔