WAsyncState<T> class
一次异步请求的状态快照(不可变)。
约定:
- Annotations
Constructors
- WAsyncState.empty()
-
加载成功但没有数据
const
- WAsyncState.failed(Object error, {T? previousData})
-
加载失败;
previousData用于刷新失败时保留旧数据。const - WAsyncState.loading({T? previousData})
-
首次请求进行中;
previousData用于刷新时保留旧数据。const - WAsyncState.ready(T data)
-
加载成功且有数据
const
Properties
- data → T?
-
final
- dataOrNull → T?
-
最近一次可用数据;loading / failed 时也可能是刷新前的旧数据。
no setter
- error → Object?
-
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- isEmpty → bool
-
no setter
- isFailed → bool
-
no setter
- isLoading → bool
-
no setter
- isReady → bool
-
no setter
- isRefreshing → bool
-
是否是在保留旧数据的前提下刷新。
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- status → WAsyncStatus
-
final
Methods
-
errorMessage(
{int maxLength = 120}) → String -
保留已有数据的错误信息(超过
maxLength时截断,避免日志/文案过长)。 -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
-
when<
R> ({required R loading(), required R ready(T data), required R empty(), required R failed(Object error)}) → R - 按状态取值,四态必须全覆盖(不可漏分支)。
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override
Static Methods
-
ofList<
E> (List< E> ? list) → WAsyncState<List< E> > - 列表类数据的便捷构造:null 或空列表都视为 empty。