我使用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,但是我不知道如何编写条件来停止更多负载,如何知道最后一页?