dio 框架介绍
A powerful Http client for Dart, which supports Interceptors, Global configuration, FormData, Request Cancellation, File downloading, Timeout etc
基于 Dart 语言编写的强大的网络请求框架,支持拦截器,全局配置,FormData,请求取消,文件下载,超时监听等
Github Dio 主页
dio 项目应用
首先在 pubspec.yaml 文件中添加 dio 库依赖并 Packages get
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
dio: ^2.1.5
然后封装基于 dio 框架的 http 请求工具类
import 'package:dio/dio.dart';
/**
* @des Dio 网络请求框架工具类
* @author liyongli 20190523
* */
class DioHttpUtils{
// 服务器接口地址公有部分
final _httpBaseUrl = "https://www.xxx...";
// 请求超时时长
final _httpConnectTimeout = 10