DioUtils class

Available Extensions

Constructors

DioUtils()
factory

Properties

dio → Dio
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addInterceptors(Interceptor interceptor) → void
添加自定义拦截器 (可以添加请求头)
asyncRequestNetwork<T>(Method method, String api, {dynamic params, Map<String, dynamic>? queryParameters, bool isShow = false, bool isPageData = false, bool isList = false, BaseModel? model, dynamic onSuccess(T? t)?, dynamic onSuccessList(List<T> list)?, dynamic onPageSuccessList(List<T> list, int total, int perPage, int currentPage)?, dynamic onError(int code, String msg)?, CancelToken? cancelToken, Options? options}) → void
brief http请求 (通过回调函数回调结果) @param method 请求方式 @param api 接口地址 @param params post请求参数 @param queryParameters get请求参数 @param isShow 请求时是否显示吐司 @param isPageData 是否是分页数据 @param isList 是否是列表数据 @param model 要解析的数据模型 @param onSuccess 请求成功回调 (返回数据) @param onSuccessList 请求成功回调 (返回列表数据) @param onPageSuccessList 请求成功回调 (返回分页列表数据) @param onError 请求失败回调 @param cancelToken 取消请求的token @param options 对请求的设置
cancelAllRequest() → void
取消所有请求
cancelRequest({String? url}) bool
根据请求地址取消特定请求 (请求) url 请求路径 比如:'trade/open'
closeProxy() → void
downloadFile(Uri uri, String savePath, AttachmentType attachmentType, {Map? data, bool showProgress = false, bool deleteOnError = true, bool isShow = false, ProgressCallback? onReceiveProgress, CancelToken? cancelToken, Options? options}) Future<bool>
brief 下载文件 (通过Future方式请求,可以使用await阻塞直到获取到结果) @param uri 文件地址 @param savePath 文件保存地址 @param showProgress 是否显示下载进度 @param deleteOnError 下载失败后删除文件 @param onReceiveProgress 接收文件进度回调 @param cancelToken 取消请求的token @param options 对请求的设置
enableConsoleLogging({bool enable = true}) → void
///////////////////////////////////////////////////////////// //////////////////////// public method ////////////////////// 是否开启控制台日志 - 仅针对debug|profile(release模式下默认关闭)
enableWindowLogging({bool enable = true}) → void
是否开启window日志 - 仅针对debug|profile(release模式下默认关闭)& 非web
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
openProxy(String proxyIp, int proxyPort) → void
开启抓包 (仅适用于非web端)
requestNetwork<T>(Method method, String url, {bool isPageData = false, bool isShow = false, dynamic params, Map<String, dynamic>? queryParameters, BaseModel? model, CancelToken? cancelToken, Options? options}) Future<BaseEntity<T>>
brief http请求 (通过Future方式请求,可以使用await阻塞直到获取到结果) @param method 请求方式 @param url 接口地址 @param isPageData 是否是分页数据 @param params post请求参数 @param queryParameters get请求参数 @param model 要解析的数据模型 @param cancelToken 取消请求的token @param options 对请求的设置
toString() String
A string representation of this object.
inherited
updateOptions({String? baseUrl, Map<String, dynamic>? headers}) → void
更改设置 (这里的更改是全局的 ====== 请注意使用) baseUrl 请求地址 headers 请求头
uploadImage<T>(String url, String filePath, AttachmentType attachmentType, {String? customAttachmentType, String? fileName, String mime = 'png', bool showProgress = false, bool isShow = false, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress, CancelToken? cancelToken, Options? options}) Future<BaseEntity<T>>
brief 上传图片 (通过Future方式请求,可以使用await阻塞直到获取到结果) @param url 接口地址 @param filePath 图片地址 @param attachmentType 上传附件类型 @param customAttachmentType 上传附件类型 (attachmentType为custom时,取customAttachmentType的值, 若为空默认为"system") @param fileName 图片名字 @param mime 图片格式 @param showProgress 是否显示上传进度 @param onSendProgress 发送文件进度回调 @param onReceiveProgress 接收文件进度回调 @param cancelToken 取消请求的token @param options 对请求的设置

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

apiSuccessCode int
getter/setter pair
defaultValidateApiSuccess ValidateApiSuccess
no setter
instance DioUtils
no setter
options ↔ BaseOptions?
getter/setter pair
validateApiSuccess ValidateApiSuccess
getter/setter pair

Static Methods

init(String baseUrl, {bool isDebugMode = false, int apiSuccessCode = 0, int sendTimeout = 15, int connectTimeout = 15, int receiveTimeout = 15, ValidateApiSuccess? validateApiSuccess}) → dynamic
///////////////////////////////////////////////////////////// //////////// 初始化DioUtils 必须初始化才能使用 ////////////////// ///////////////////////////////////////////////////////////// 初始化DioUtil的参数 (也可以使用initOption) **** 切记在使用DioUtils前初始化,推荐在main入口函数中调用 **** baseUrl 请求地址 isDebugMode 调试模式, debug时会打印接口日志到控制台,弹出接口错误提示 apiSuccessCode api接口正确码 sendTimeout 发送超时时间 (秒) connectTimeout 请求超时时间 (秒) receiveTimeout 接收超时时间 (秒) validateApiSuccess 根据返回的数据判断是否请求成功的闭包
initOption(BaseOptions options, {bool isDebugMode = false, int apiSuccessCode = 0, ValidateApiSuccess? validateApiSuccess}) → dynamic
初始化DioUtil的参数 **** 切记在使用DioUtils前初始化,推荐在main入口函数中调用 **** options 构建dio时用到的配置 isDebugMode 调试模式, debug时会打印接口日志到控制台,弹出接口错误提示 apiSuccessCode api接口正确码 validateApiSuccess 根据返回的数据判断是否请求成功的闭包