用流构建loadmore listview

时间:2018-08-07 04:40:59

标签: dart flutter

我使用Future在Flutter中建立了基本的分页列表视图,它似乎运行良好:

  Future loadNext() async {
    if (!isPerformingRequest && isLoadMore) {
      setState(() => isPerformingRequest = true);

      int page = (objects.length / widget.pageSize).ceil() + 1;
      List<T> fetched = await widget.pageRequest(page, pageSize);

      if (fetched == null ||
          fetched.length == 0 ||
          fetched.length < pageSize) {
        this.setState(() {
          isLoadMore = false;
        });
      }

      if (mounted) {
        this.setState(() {
          //this.addObjects(fetched);
          objects.addAll(fetched);
          isPerformingRequest = false;
        });
      }
    }
  }

现在我想改为使用stream和streambuilder,但是我不知道如何编写条件来停止更多负载,如何知道最后一页?

0 个答案:

没有答案