Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

不触发onRefresh 或者 onLoad 前, 无法设置Footer状态为NoMore #880

Open
seanLee opened this issue Dec 4, 2024 · 1 comment
Open

Comments

@seanLee
Copy link

seanLee commented Dec 4, 2024

已经查阅过相关资料, 也在issues里面搜索过, 但是现在确实遇到了同样的问题, 这是加载代码

void initState() {
    super.initState();

    controller = Get.put(ExploreController(), tag: widget.category);
    _refreshController = EasyRefreshController(
        controlFinishRefresh: true, controlFinishLoad: true);

    controller.state.isLoading = true;
    refreshFirst();
  }

  Future<void> refreshFirst() async {
    await refresh();
  }

  Future<void> refresh() async {
    _willLoadMore = false;
    _currentPage = 1;
    await loadData();
  }

  Future<void> refreshMore() async {
    _willLoadMore = true;
    _currentPage += 1;
    await loadData();
  }

  Future<void> loadData() async {
    var categoryList =
        await ExploreApi.getPageList(widget.category, _currentPage);

    _refreshController.finishRefresh();
    controller.state.isLoading = false;
    _canLoadMore =
        ((controller.state.itemList.length + categoryList.items.length) <
            categoryList.total);
    if (_willLoadMore) {
      final list = controller.state.itemList;
      controller.state.itemList = list.addAll(categoryList.items);
    } else {
      controller.state.itemList = categoryList.items;
    }
   _refreshController.finishLoad(IndicatorResult.noMore));
  }

目前的情况是默认进来加载, 还是可以加载更多, 但是如果触发一次onRefresh方法后, 就会显示NoMore的样式.
以下是RefreshView的使用方法:

EasyRefresh(
                  resetAfterRefresh: false,
                  controller: _refreshController,
                  header: const ClassicHeader(),
                  footer: const ClassicFooter(),
                  onRefresh: () async {
                    await Future.delayed(const Duration(milliseconds: 500));
                    if (!mounted) {
                      return;
                    }

                    await refresh();
                  },
                  onLoad: () async {
                    await Future.delayed(const Duration(milliseconds: 500));
                    if (!mounted) {
                      return;
                    }

                    if (_canLoadMore) {
                      refreshMore();
                    }
                    _refreshController.finishLoad(_canLoadMore ? IndicatorResult.success : IndicatorResult.noMore);
                  },
                  child: AnyScrollView
)

确实无法提供Demo, 但是如果项目的example中可以提供真实的网络请求方法, 而不是模拟会不会更好

@xuelongqy
Copy link
Owner

请在第一帧后(addPostFrameCallback)进行设置。在没有渲染第一帧之前,state是不存在的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants