updateRefreshResult<T> method

void updateRefreshResult<T>(
  1. Result result, {
  2. required int page,
  3. bool force = false,
  4. int? limitPage,
  5. int? pageCount,
  6. bool? noMore,
  7. BaseComputeResult? compute,
})

noMore - 没有更多? 没有更多数据: true, 有更多数据: false

Implementation

void updateRefreshResult<T>(Result result,
    {required int page,
    bool force = false,
    int? limitPage,
    int? pageCount,
    bool? noMore,
    BaseComputeResult? compute}) {
  dynamic models = result.models.toList();
  if (result.valid) {
    if (models.isNotEmpty) {
      bool noMoreJudge = noMore ?? true;
      if (noMore == null) {
        if (pageCount != null) {
          noMoreJudge = page >= pageCount;
        } else if (kPageCountKey.isNotEmpty) {
          noMoreJudge = page >= result.count;
        } else {
          noMoreJudge = models.length < (limitPage ?? kLimitPage);
        }
      }
      logDebug("$noMore, $noMoreJudge");

      this.page = page;
      if (page > kFirstPage) {
        // 上拉加载第2页数据
        dynamic _tmp = state;
        _tmp.addAll(models);
        compute != null
            ? compute(_tmp, RxStatus.success())
            : change(_tmp, status: RxStatus.success());
        finishLoad(success: result.valid, noMore: noMoreJudge);
      } else {
        // 下拉刷新第1页数据
        compute != null
            ? compute(models, RxStatus.success())
            : change(models, status: RxStatus.success());
        finishRefresh(success: result.valid, noMore: noMoreJudge);
      }
    } else if (page == kFirstPage && state != null) {
      // 下野刷新时已有数据
      if (force) {
        // 强制下拉刷新时,无数时会清除数据
        compute != null
            ? compute(
                null, RxStatus.error(_placeholderEmptyTitle ?? kEmptyList))
            : change(null,
                status: RxStatus.error(_placeholderEmptyTitle ?? kEmptyList));
      }
      finishRefresh(success: result.valid, noMore: false);
    } else if (state == null) {
      // 未约定的无数据
      compute != null
          ? compute(
              null, RxStatus.error(_placeholderEmptyTitle ?? kEmptyList))
          : change(null,
              status: RxStatus.error(_placeholderEmptyTitle ?? kEmptyList));
      finishRefresh(success: true, noMore: true);
    } else {
      // 已经有1页数据再次上拉加载 无更多数据
      finishLoad(success: result.valid, noMore: true);
    }
  } else {
    if (page > kFirstPage) {
      finishLoad(success: result.valid, noMore: true);
    } else {
      finishRefresh(success: result.valid, noMore: false);
    }
    dynamic tmp = state;
    compute != null
        ? compute(tmp, RxStatus.error(result.message))
        : change(tmp, status: RxStatus.error(result.message));
    showToast(result.message);
  }
}