BuildRequest<T> class
create_user: zhengzaihong email:1096877329@qq.com create_date: 2025-08-12 create_time: 17:22 describe: 优化 RxNet职责,将BuildRequest从RxNet中分离出来, update_date: 2025-10-03 主要改进:
- 引入RequestBodyType枚举,明确参数发送方式
- 优化RESTful参数处理,支持路径参数和查询参数分离
- 改进缓存键生成逻辑
- 统一错误处理
- 更流畅的API设计
Constructors
- BuildRequest(HttpType _httpType, RxNet _rxNet)
Properties
- checkNetWork ↔ CheckNetWork?
-
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- onResponse ↔ dynamic Function(Response response)?
-
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addHeaders(
Map< String, dynamic> headers) → BuildRequest<T> -
addParams(
Map< String, dynamic> params) → BuildRequest<T> - 兼容旧API:addParams
-
asFormData(
) → BuildRequest< T> - 使用FormData格式发送(multipart/form-data)
-
asJson(
) → BuildRequest< T> - 使用JSON格式发送(application/json)
-
asUrlEncoded(
) → BuildRequest< T> - 使用URL编码格式发送(application/x-www-form-urlencoded)
-
breakPointDownload(
{required String savePath, ProgressCallback? onReceiveProgress, Success? success, Failure? failure, Completed? completed, dynamic cancelCallback()?}) → void - 断点下载
-
breakPointUpload(
{required String filePath, ProgressCallback? onSendProgress, Success? success, Failure? failure, Completed? completed, dynamic cancelCallback()?, int? start}) → void - 断点上传
-
download(
{required String savePath, ProgressCallback? onReceiveProgress, Success? success, Failure? failure, Completed? completed}) → void - 下载文件
-
execute<
T> ({Success< T> ? success, Failure? failure, Completed? completed}) → void - 使用回调的方式
-
executeStream<
T> () → Stream< RxResult< T> > - Stream方式(支持轮询)
-
getCancelToken(
) → CancelToken? -
getContentLength(
Response response) → Future< String?> - 获取内容长度
-
getParams(
ParamCallBack callBack) → BuildRequest< T> -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
removeNullValueKeys(
) → BuildRequest< T> -
request<
T> () → Future< RxResult< T> > - async/await方式
-
setBodyParam(
String key, dynamic value) → BuildRequest< T> - 设置Body参数(用于POST/PUT/PATCH)
-
setBodyParams(
Map< String, dynamic> params) → BuildRequest<T> - 批量设置Body参数
-
setBodyType(
RequestBodyType type) → BuildRequest< T> - 设置请求体类型
-
setCacheInvalidationTime(
int millisecond) → BuildRequest< T> -
setCacheMode(
CacheMode cacheMode) → BuildRequest< T> -
setCancelToken(
CancelToken cancelToken) → BuildRequest< T> -
setCheckNetwork(
CheckNetWork checkNetWork) → BuildRequest< T> -
setContentType(
String type) → BuildRequest< T> -
setEnableGlobalHeader(
bool enable) → BuildRequest< T> -
setHeader(
String key, dynamic value) → BuildRequest< T> -
setIgnoreCacheKey(
String key) → BuildRequest< T> -
setIgnoreCacheKeys(
List< String> keys) → BuildRequest<T> -
setJsonConvert(
JsonTransformation convert) → BuildRequest< T> -
setLoop(
bool loop, {Duration? interval}) → BuildRequest< T> -
setOptionConfig(
OptionConfig callBack) → BuildRequest< T> -
setParam(
String key, dynamic value) → BuildRequest< T> - 兼容旧API:setParam - 根据HTTP方法自动判断参数类型
-
setParams(
Map< String, dynamic> params) → BuildRequest<T> - 兼容旧API:setParams
-
setPath(
String path) → BuildRequest< T> -
setPathParam(
String key, dynamic value) → BuildRequest< T> - 设置路径参数(用于RESTful风格) 例如:setPathParam("id", "123") 会将 /user/{id} 替换为 /user/123
-
setPathParams(
Map< String, dynamic> params) → BuildRequest<T> - 批量设置路径参数
-
setQueryParam(
String key, dynamic value) → BuildRequest< T> - 设置查询参数(拼接在URL后) 例如:setQueryParam("page", 1) 会生成 ?page=1
-
setQueryParams(
Map< String, dynamic> params) → BuildRequest<T> - 批量设置查询参数
-
setRawBody(
dynamic body) → BuildRequest< T> - 设置原始Body数据(用于自定义body)
-
setRequestIgnoreCacheTime(
bool ignoreCache) → BuildRequest< T> -
setResponseCallBack(
dynamic responseCallBack(Response response)) → BuildRequest< T> -
setResponseType(
ResponseType type) → BuildRequest< T> -
setRestfulUrl(
bool restful) → BuildRequest< T> - 兼容旧API:setRestfulUrl 新版本会自动检测路径中的占位符,无需手动设置
-
setRetryCount(
int count, {Duration? interval}) → BuildRequest< T> -
toBodyData(
) → BuildRequest< T> - 兼容旧API:toBodyData
-
toFormData(
) → BuildRequest< T> - 兼容旧API:toFormData
-
toString(
) → String -
A string representation of this object.
inherited
-
toUrlEncoded(
) → BuildRequest< T> - 兼容旧API:toUrlEncoded
-
upload(
{ProgressCallback? onSendProgress, Success? success, Failure? failure, Completed? completed}) → void - 上传文件
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited