Skip to main content

w_tools_async 7.3.0 copy "w_tools_async: ^7.3.0" to clipboard
w_tools_async: ^7.3.0 copied to clipboard

w_tools 的异步层:执行、重试、超时、取消、四态状态、Controller 与可复用异步视图。

Changelog #

7.0 迁移见 async-7.0。

7.3.0 #

Added #

  • 新增 WAsyncHooks 值对象与 WAsync.defaultHooks;run / tryRun / retry / timeout / settle 增加 hooks 参数。
  • 解析优先级:显式回调 → 本次 hooks → WAsync.defaultHooks; 传 WAsyncHooks.none 可关闭本次默认。

7.2.0 #

Added #

  • WAsync.retry / WAsync.timeout 增加 onStart / onFinally;整次操作各一次, onRetry 仍按 attempt 调用。
  • WAsync.settle 增加 batch-level onStart / onFinally:整批各一次; onError 仍按失败任务调用;空集合 / 已取消 token 不调用。

7.1.0 #

Added #

  • WAsync.run / WAsync.tryRun 增加可选 onStart / onFinally: onStart 在任务开始前调用,onFinally 在成功 / 失败 / 取消后调用; onFinally 在 onError 之后执行,三个回调自身异常均不影响任务结果。
  • app 可以用钩子管理 loading 框,不再需要通用 _withLoading 包装;WAsync 仍不内置 UI。

7.0.2 #

Changed #

  • 文档:README 增加可选包 w_tools_async_ui 的规范入口链接; WAsyncTheme 的根装配示例改指 WAppOptions.appWrapper。

7.0.1 #

Fixed #

  • WAsyncPagedController.loadMore 恢复 generation 守卫:onError 回调里重入 refresh() / replaceData() 时,旧的 loadMore 失败不再在刷新之后写回 snapshot.loadMoreError,footer 不会误显示 failed。
  • 补两条回归测试:onError 内 refresh / replaceData。

7.0.0 #

Breaking #

  • 执行层收敛:删除 WAsync.parallel / WAsync.pool / WAsync.serial / WAsync.first / WAsync.map;并发直接用 Future.wait / Future.any / package:async,独立区块用 settle。
  • 删除 WAsyncOptions / WAsyncActivity:tryRun / run / retry / timeout / settle 改收 onError 参数;不再有 activity 计数。
  • 删除 WAsyncStateBuilder;滚动组件放进 WAsyncView.readyBuilder,sliver 用 WAsyncStateSliver。
  • 删除 WAsyncThemeViews(不再从 barrel 导出,内部保留)与 WAsyncRetryErrorHandler; 删除 WAsyncView.onRetryError / WAsyncStateSliver.onRetryError;onRetry 类型改为 VoidCallback?。
  • WAsyncController 构造函数收敛:loader 统一接收 WCancelToken;删除 WAsyncController.withToken / WAsyncController.listWithToken / WAsyncController.retry / WAsyncController.reload。
  • WAsyncPagedController 构造函数收敛:loader 统一接收 (int page, WCancelToken token) 并返回 WAsyncPage<T>;删除 WAsyncPagedController.withToken / WAsyncPagedController.withPage / WAsyncPagedController.withPageToken。
  • 分页观察面收敛:新增 WAsyncPagedSnapshot;删除 WAsyncPagedController.page / WAsyncPagedController.initialPage / WAsyncPagedController.hasLoadedMoreThanOnePage / WAsyncPagedController.isLoadingMore / WAsyncPagedController.loadMoreError / WAsyncPagedController.hasMore / WAsyncPagedController.hasMoreListenable / WAsyncPagedController.changes / WAsyncPagedController.footerStatus。 replaceData 删除 page 参数。
  • 删除 WAsyncPage.fromTotal;WAsyncPageLoader 改为 (page, token) => Future<WAsyncPage<T>>;删除 WAsyncTokenPageLoader。
  • 删除 WAsyncTheme.sliverLoadingBuilder / WAsyncTheme.sliverEmptyBuilder / WAsyncTheme.sliverErrorBuilder / WAsyncTheme.sliverErrorBannerBuilder / WAsyncTheme.refreshingSliverBuilder;sliver 复用普通 builder。
  • 删除 WAsyncState.ofList、WCancelToken.clearListeners。
  • 默认错误视图不再渲染异常原文:WAsyncErrorView / WAsyncErrorBanner 改为 title + 可选 message,删除构造参数 error。
  • 分页追加不再使用 _ChunkedList 结构共享,回到 List.unmodifiable。
  • 构造函数 / 签名变化:WAsyncController.new、WAsyncPagedController._、WAsyncTheme.new、 WAsyncErrorView.new、WAsyncErrorBanner.new、WAsyncErrorView.error、 WAsyncErrorBanner.error、WAsyncPagedController.replaceData、 WAsyncStateSliver.refreshingSliverBuilder。

Changed #

  • WAsyncView 在宽高都有界时用固定槽 Column:错误条 / 刷新条占位,不遮挡内容; 普通内容保持自身高度,滚动内容拿满可用高度;任一维无界时仍是内容盒 overlay。
  • settle 的 onError 按失败任务逐个通知(不再有 activity 合并计数)。
  • WAsyncView / WAsyncStateSliver 的默认错误视图只显示文案标题,错误详情走日志 / onError。
  • WAsyncController.load 的 isEmpty / normalize 抛错转为 failed 并通知 onError, 不再让 load() 的 Future 裸 reject。
  • 分页 refresh 期间 footer 返回 hidden(loadMore 会被忽略);refresh 结束发一次最新 快照,恢复 loadMore / noMore,不会停在旧状态。

Added #

  • WAsyncPagedSnapshot:分页唯一观察入口(state / footerStatus / loadMoreError / hasMore / isLoadingMore)。
  • WAsyncPagedController.state 保留为只读 adapter,直接喂给 WAsyncView。

6.8.0 #

Added #

  • WAsyncPage.fromTotal(items:, total:, page:, pageSize:):按总条数 / 页大小计算 hasMore; total == null 时回退 hasMore:null,page 从 1 开始。

6.7.0 #

Added #

  • WAsyncController.reload():与 load() 等价的明确命名。

Deprecated #

  • WAsyncController.retry():改用 reload(),remove-in 7.0.0;自动重试用 WAsync.retry。

6.6.0 #

Added #

  • WAsyncStrings.loading(默认 Loading):默认 loading 视图的可本地化文案,同时作为 Semantics.label。
  • 默认 loading / empty / error / banner 视图带 Semantics(liveRegion: true);状态切换 会被读屏播报。显式 / theme builder 不自动加语义。

6.5.0 #

Added #

  • WAsyncPagedFooterStatus + WAsyncPagedController.footerStatus:派生 footer 的 hidden / loading / failed / noMore / loadMore;footer 用 changes 监听, 不新增通知源。

6.4.0 #

Added #

  • WAsync.settle:并发执行任务工厂并等待全部 settle,单个失败不会让整批抛错; 结果按输入顺序返回 WAsyncResult,默认最多 4 个并发。
  • WAsyncController.replaceData:单区块乐观更新,取消在飞 load,旧结果不写回。
  • WAsyncController.listWithToken:列表语义 + 感知取消;空列表归 empty, state.data 为 unmodifiable。
  • WAsync.retry 新增 retryDelayBuilder / onRetry:支持指数退避与每次重试观测; onRetry 自身异常会被忽略,不影响重试结果。

Fixed #

  • WAsync.tryRun 的取消 / 失败竞态:token 已取消时,非 Error 的失败按 WAsyncCancelled 处理;Error 仍返回 WAsyncFailure,避免吞掉编程错误。
  • WAsync.timeout 的 TimeoutException 带上时长(duration),便于排查超时配置。

6.3.0 #

Added #

  • WAsyncPage<T> + WAsyncPagedController.withPage / withPageToken: loader 可显式返回 hasMore,第一页不足一页或已知 total 时不再多发一次空页请求。
  • 旧构造 WAsyncPagedController(loader) / withToken 行为不变:本页非空仍视为有更多。

6.2.0 #

Added #

  • WAsyncPagedController.replaceData(List<T> data, {int? page, bool? hasMore}): 本地替换 / 乐观更新入口。会取消在飞 refresh / loadMore,避免旧结果覆盖本地修改; page / hasMore 默认沿用当前值,空列表默认没有更多。

Fixed #

  • WAsyncPagedController.refresh() 在刷新在飞时不再静默返回:新调用会取消上一次请求并以 新参数重发,旧结果不会写回 state;刷新失败保留上一次成功的页号与 hasMore。
  • WAsyncStateSliver 的 failed + 旧数据错误条移到列表上方,长列表下不再落在末尾; 错误条出现 / 消失不会重建 ready 子树。

6.1.0 #

Added #

  • WAsyncPagedController.page:下一次 loadMore 将请求的页码(首屏完成前等于 initialPage,刷新失败会回滚)。消费方不用再自己维护「是否翻过页」的布尔。
  • WAsyncPagedController.hasLoadedMoreThanOnePage:是否已成功追加过第二页 (page > initialPage + 1),由 page 派生,刷新失败回滚时不会误报。

Changed #

  • WAsyncView / WAsyncStateBuilder 的 dartdoc 说明 state 是 ValueListenable、 不是 Rx:页面里其它 Rx 状态上的 Obx 仍需保留,删掉不会编译报错但会静默失效。

6.0.0 #

Breaking #

  • WAsyncController / WAsyncPagedController 的 options: WAsyncOptions? 改为 onError: void Function(Object)?;控制器不再接受 activity。迁移见 async-6.0。
  • WAsyncOptions.onError 从 void Function(Object?)? 改为 void Function(Object)?。
  • WAsyncErrorWidgetBuilder 的 retry 从 VoidCallback 改为 VoidCallback?;无 retry 时 自定义 / 主题 builder 仍会被调用并收到 null,包内默认视图不渲染按钮。
  • WAsyncController.list 的 state.data 改为 unmodifiable 列表,与 WAsyncPagedController 一致;原地修改会抛 UnsupportedError。

Changed #

  • WAsyncPagedController 的追加改为内部 chunked 不可变列表(结构共享):每页只复制 最后一个 chunk(≤256)与外层引用,旧 state.data 共享前缀;state.data 仍是 List<T>。

Docs #

  • README 写明分页追加的 chunked 结构与结构共享语义(十万级不会整表复制)。

Removed #

  • WAsyncState.errorMessage:未使用的半成品 API,6.0 移除;需要截断错误文案时自己处理。

Internal #

  • 去掉控制器 / sliver 的不可达取消分支与 pool 的死 fallback。

5.2.0 #

Added #

  • WAsyncState.list:与 WAsyncController.list 对称的列表状态构造;旧名 ofList 标 @Deprecated,7.0 删除。
  • WAsyncPagedController.changes:合并 state / isLoadingMore / loadMoreError / hasMoreListenable 的单监听入口,footer 不必再挂四个监听。

Changed #

  • WAsyncErrorBanner 默认文案的冒号改为 ASCII : ,避免英文 title 与全角标点混排。
  • 分页追加改用 List.unmodifiable(current.followedBy(value)),去掉一次中间列表拷贝。

Docs #

  • 说明 WAsyncController 原样保存 loader 返回值,WAsyncPagedController.state.data 为 unmodifiable 列表。

5.1.0 #

Changed #

  • WAsyncController / WAsyncPagedController 传入 WAsyncOptions.activity 现在在构造时抛 ArgumentError(release 也一样),不再在 release 下静默忽略。控制器自己维护四态; 需要并发活动计数请直接用 WAsync。

Docs #

  • 修正已删除 API / 旧 null 语义的过期注释;补充并发组合器边界与分页 footer 的 hasMoreListenable 说明,并补齐结果三态 getter、theme 通知、sliver / view retry 错误等测试。

5.0.1 #

Changed #

  • README 补充 WAsyncView 的 per-view builder、WAsyncStatus 与 WAsyncActivity 适用边界。

5.0.0 #

Breaking #

  • WAsync.run / map / retry / timeout / parallel / pool / first / serial 现在直接返回成功值;失败抛异常,取消抛 WCancellationException,不再用 null 吞错。
  • 新增 WAsyncResult / WAsyncSuccess / WAsyncFailure / WAsyncCancelled;WAsync.tryRun 返回结果对象。
  • 删除 WAsync.runValue;用 WAsync.run。
  • WAsyncLoading 改名 WAsyncActivity;WAsyncOptions.loading 改名 activity,withoutLoading 改名 withoutActivity。
  • 删除 WAsyncOptions.copyWith;直接构造 options。
  • 删除 WAsyncState.dataOrNull;统一用 data。
  • WAsyncView.onRetry 改为可选;无 retry 时不渲染重试按钮。
  • 默认文案改由 WAsyncStrings 提供(默认为中性英文),可通过 WAsyncTheme.strings 注入。
  • 分页 initialPage 必须 >= 1。

Added #

  • WAsyncOptions.withoutOnError():调用点自己处理错误时去掉兜底 onError,避免重复上报。

4.1.0 #

Added #

  • WAsyncThemeViews:四态视图的统一解析入口(显式 builder > WAsyncTheme > 包内默认)。 WAsyncStateBuilder 这类自建滚动壳也能复用全局默认,不必每页重写 loading / empty / error。
  • WAsyncTokenLoader + WAsyncController.withToken、 WAsyncTokenPageLoader + WAsyncPagedController.withToken:loader 能拿到 WCancelToken,取消真正能传到请求层。
  • WAsync.runValue:直接返回结果,不写 onSuccess 映射。
  • WAsyncPagedController.hasMoreListenable:footer 可单独监听「加载更多 / 没有更多」。
  • WAsyncOptions.withoutLoading();copyWith 传错类型抛 ArgumentError,不再留到调用时炸。

Changed #

  • WAsyncStateSliver 在 onRetry == null 时使用不带重试按钮的默认视图,不再渲染 点了没反应的按钮;该配置下不调用自定义 error / banner builder(它们要求可用的 retry)。
  • WAsync.run / retry / serial / pool 取消时会尽快返回 null,与 timeout / parallel / first 对齐;底层任务仍继续执行,结果被丢弃。
  • 控制器把失败(含 Error)统一回调 options.onError,编程错误不再完全静默。
  • 控制器构造时断言 options.loading == null(控制器自己维护四态,传了会被忽略)。
  • WAsyncPagedController.refresh() 会取消在途 loadMore 的 token;loadMore 同样传入 token。
  • WAsyncLoading.begin / end 保持公开(聚合包 API 契约),文档明确为框架内部使用。

Docs #

  • 修正 docs/modules/async_module.md 模块结构里的已删除文件,README 安装版本同步。

4.0.0 #

Breaking #

  • WAsyncStateSliver.state 改为 ValueListenable<WAsyncState<T>>,与 WAsyncView / WAsyncStateBuilder 一致;onRetry 改为 Future<void> Function()?。 迁移:state: state → state: controller.state,onRetry: () {} → onRetry: controller.load。

3.0.0 #

Removed #

  • WAsyncViewDefaults / WAsyncSliverDefaults:统一用 WAsyncTheme 的普通 builder 与 sliver*Builder。

2.1.0 #

Added #

  • WAsyncTheme:把普通视图与 sliver 视图的默认 loading / empty / error / 刷新 builder 合到一个 InheritedWidget,放在 App 根部一次装完;显式 builder 仍然优先。

Deprecated #

  • WAsyncViewDefaults / WAsyncSliverDefaults:3.0 移除,改用 WAsyncTheme 的对应字段 (sliver*Builder 前缀区分 sliver 视图)。旧类仍被识别(优先级低于 WAsyncTheme)。

2.0.0 #

Breaking #

  • WAsyncConfig 改名为 WAsyncOptions 并改为纯数据:删除 showLoading / onLoadingStart / onLoadingEnd / fallbackOnError 字段和 7 个转发方法(config.run(...) 等),统一用 WAsync.xxx(options: ...)。
  • 加载状态合并改为显式 WAsyncLoading(放进 WAsyncOptions.loading):不传就完全不跟踪,不再“共享配置即隐式合并”。
  • 方法改名:runWithRetry → retry、runWithTimeout → timeout、wait → parallel、runAllWithConcurrency → pool、any → first、sequence → serial。
  • 删除 WAsyncBuilder 兼容别名(使用 WAsyncStateBuilder)。
  • WAsyncController / WAsyncPagedController 新增 options 参数,内部改走 WAsync;load / refresh 会取消上一次的 WCancelToken,dispose 也会取消(取消仍是协作式的)。

Added #

  • WAsyncLoading:onStart / onEnd / isLoading / begin() / end()。
  • WAsyncOptions.copyWith 用哨兵实现,传 null 可清空 loading / onError。

Fixed #

  • 非法参数(负数 retryCount / retryDelay / timeout、concurrency < 1)以失败的 Future 返回 ArgumentError,与旧行为一致。

1.0.0 #

首次发布。

  • WAsync / WAsyncConfig / WCancelToken:执行、重试、超时、并发控制与取消。
  • WAsyncState / WAsyncStatus:四态异步状态快照。
  • WAsyncController:每个异步区块独立管理状态、旧请求丢弃与手动重试。
  • WAsyncView / WAsyncErrorView / WAsyncErrorBanner / WAsyncViewDefaults:异步视图、默认错误态与刷新错误条。
  • WAsyncStateBuilder:滚动页面 / SmartRefresher / CustomScrollView 的状态构建入口。
  • WAsyncBuilder:WAsyncStateBuilder 的兼容别名。
  • WAsyncPagedController:分页列表的首屏、刷新、追加、hasMore 与 loadMore 错误。
  • WAsyncStateSliver:CustomScrollView 的四态 sliver、failed+旧数据;默认不额外添加 refreshing 进度。
  • WAsyncSliverDefaults:Sliver 页面独立的默认 loading/empty/error/banner 与 refreshing sliver。
  • WAsyncPagedController 的 initial: WAsyncState.ready(...) 下一次 loadMore() 从 initialPage + 1 开始,避免重复追加第一页。
0
likes
0
points
3.46k
downloads

Publisher

unverified uploader

Weekly Downloads

w_tools 的异步层:执行、重试、超时、取消、四态状态、Controller 与可复用异步视图。

Homepage
Repository (GitHub)
View/report issues

Topics

#flutter #async #state #ui

License

unknown (license)

Dependencies

flutter

More

Packages that depend on w_tools_async