HttpUtil class

HTTP 请求工具类 基于 Dio 封装,支持配置化的请求头注入

Available extensions

Properties

hashCode int
The hash code for this object.
no setterinherited
isLoading HttpUtilWithLoading

Available on HttpUtil, provided by the HttpUtilLoadingExtension extension

获取带加载提示的 HttpUtil 实例 用于链式调用,整个链路共享一个加载提示
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

downloadFile({required String path, required String savePath, Map<String, dynamic>? queryParameters, Map<String, String>? headers, void onProgress(int received, int total)?, CancelToken? cancelToken, bool deleteOnError = true, bool resumeOnError = true, String? baseUrl, String? service}) Future<DownloadResponse<String>>

Available on HttpUtil, provided by the HttpUtilFileDownload extension

下载文件
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
request<T>({required String method, required String path, dynamic data, Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress, String? baseUrl}) Future<Response>
请求方法(返回 Dio Response) method 请求方式:必须使用 hm.get、hm.post 等常量 baseUrl 可选的 baseUrl,如果提供则覆盖默认 baseUrl
send<T>({required String method, required String path, dynamic data, Map<String, dynamic>? queryParameters, bool isLoading = false, Map<String, String>? headers, int priority = 0, bool skipDeduplication = false, bool skipQueue = false, String? baseUrl, String? service, bool isChainCall = false, void onFailure(int? httpStatusCode, int? errorCode, String message)?}) Future<Response<T>>

Available on HttpUtil, provided by the HttpUtilSafeCall extension

发送请求(自动处理异常,失败时自动提示) method 请求方式:必须使用 hm.get、hm.post 等常量 isLoading 是否显示加载提示(默认 false) 如果为 true 且配置了 contextGetter,将自动显示加载提示 headers 特定请求的请求头(可选),会与全局请求头合并,如果键相同则覆盖全局请求头
sseManager() SSEManager

Available on HttpUtil, provided by the HttpUtilSSE extension

创建 SSE 连接管理器
toString() String
A string representation of this object.
inherited
uploadFile<T>({required String path, dynamic file, String fieldName = 'file', String? fileName, String? contentType, Map<String, dynamic>? additionalData, Map<String, dynamic>? queryParameters, void onProgress(int sent, int total)?, CancelToken? cancelToken, Map<String, String>? headers}) Future<Response<T>>

Available on HttpUtil, provided by the HttpUtilFileUpload extension

上传单个文件
uploadFiles<T>({required String path, required List<UploadFile> files, Map<String, dynamic>? additionalData, Map<String, dynamic>? queryParameters, void onProgress(int sent, int total)?, CancelToken? cancelToken, Map<String, String>? headers}) Future<Response<T>>

Available on HttpUtil, provided by the HttpUtilFileUpload extension

上传多个文件
uploadToUrlResponse<T>({required String uploadUrl, required dynamic file, String method = 'PUT', Map<String, String>? headers, void onProgress(int sent, int total)?, CancelToken? cancelToken}) Future<Response<T>>

Available on HttpUtil, provided by the HttpUtilFileUpload extension

直接上传文件到外部 URL(OSS 直传)

Operators

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

Static Properties

dio → Dio
获取 Dio 实例(公开访问,方便特殊处理) 注意:使用前必须先调用 configure() 进行配置
no setter
instance HttpUtil
单例获取
no setter
requestQueue RequestQueue?
获取请求队列管理器(如果已配置)
no setter

Static Methods

configure(HttpConfig config) → void
配置 HTTP 工具类(必须在首次使用前调用)
createDio({String? baseUrl, Duration? connectTimeout, Duration? receiveTimeout, Duration? sendTimeout}) → Dio
创建独立的 Dio 实例(不依赖当前配置) 适用于需要自定义 baseUrl 或不需要拦截器的场景