DownloadResponse<T> class

文件下载响应 用于表示文件下载的结果

Inheritance

Constructors

DownloadResponse({required bool isSuccess, String? errorMessage, String? filePath, int? totalBytes, T? data})

Properties

data → T?
下载的响应数据(通常为 null,因为下载的是文件)
final
errorCode int?
错误码(如果失败,业务错误码) 默认返回 null,用户可以在自己的响应类中重写此方法返回具体的错误码
no setterinherited
errorHandled bool
错误是否已被处理(通过链式调用的 onFailure 回调或 send 的 onFailure 回调) 如果为 true,表示错误已经通过错误处理回调处理,不应该再调用全局的 onFailure
no setterinherited
errorMessage String?
错误消息(如果下载失败)
final
filePath String?
下载的文件路径(如果成功)
final
hashCode int
The hash code for this object.
no setterinherited
httpStatusCode int?
HTTP 状态码(如 200, 404, 500 等) 默认返回 null,用户可以在自己的响应类中重写此方法返回 HTTP 状态码
no setterinherited
isSuccess bool
是否下载成功
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
totalBytes int?
下载的总字节数
final

Methods

extract<R>(R? extractor(T? data)) → R?
提取数据(自动处理类型转换) 仅在成功时执行提取器 内部已处理异常,用户不需要 try-catch
inherited
extractField<R>(String key) → R?
从 Map 中提取字段(最简单的方式) 适用于从 Map<String, dynamic> 中直接获取字段值
inherited
extractList<R>(String key, R fromJson(Map<String, dynamic> json)) List<R>
从 Map 中提取列表字段并转换为模型列表 适用于从 Map<String, dynamic> 中提取 List 字段并转换为模型列表
inherited
extractModel<R>(R? fromJson(Map<String, dynamic> json)) → R?
从 Map 提取模型(类型安全,自动处理类型检查和异常) 适用于从 Map<String, dynamic> 转换为模型类
inherited
extractPath<R>(String path) → R?
从 Map 中提取嵌套字段(支持路径,如 'user.name') 适用于从 Map<String, dynamic> 中提取嵌套字段值
inherited
getData() → T?
获取数据(类型安全)
inherited
handleError() → void
处理错误(可选实现,工具类会调用此方法) 默认实现为空,用户可以在自己的响应类中重写
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onFailure(void callback(int? httpStatusCode, int? errorCode, String message)) Response<T>
失败时执行回调 返回自身,支持链式调用 注意:如果调用了此方法,错误将被标记为已处理,全局的 onFailure 不会再被调用
inherited
onSuccess(VoidCallback callback) Response<T>
成功时执行回调 返回自身,支持链式调用
inherited
toString() String
A string representation of this object.
inherited

Operators

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

Static Methods

failure<T>({required String errorMessage}) DownloadResponse<T>
创建失败响应
success({required String filePath, int? totalBytes}) DownloadResponse<String>
创建成功响应