安全证查询官网,安徽seo团队,可以做网站背景音乐的英文歌曲,如何做网站?在Flutter中实现网络请求有很多模块#xff0c;可以使用http模块#xff0c;也可以使用dio模块。
具体的用法在https://pub.dev/上面有#xff0c;我们以前的的项目中用的是Dio库#xff0c;它支持get post put delete还支持文件的上传下载。
import ‘package:dio/dio.d…在Flutter中实现网络请求有很多模块可以使用http模块也可以使用dio模块。
具体的用法在https://pub.dev/上面有我们以前的的项目中用的是Dio库它支持get post put delete还支持文件的上传下载。
import ‘package:dio/dio.dart’;final dio Dio();void getHttp() async {
final response await dio.get(‘https://dart.dev’);
print(response);
}import ‘package:dio/dio.dart’;class HttpsClient {
static String domain “https://xiaomi.itying.com/”;
static Dio dio Dio();
HttpsClient() {
dio.options.baseUrl domain;
dio.options.connectTimeout const Duration(milliseconds: 5000); //5s
dio.options.receiveTimeout const Duration(milliseconds: 5000);
}Future get(apiUrl) async {
try {
var response await dio.get(apiUrl);
return response;
} catch (e) {
print(“请求超时”);
return null;
}
}Future post(String apiUrl, {Map? data}) async {
try {
var response await dio.post(apiUrl, data: data);
return response;
} catch (e) {
print(“请求超时”);
return null;
}
}
}
源自Dart Flutter入门实战基础教程下载地址-2023年录制