flutter - 为什么当我向下滚动时我的颤动滚动监听器会多次调用
问题描述
每次滚动以获取新数据时,我都有重复的数据,如果我只在文档末尾执行一次滚动但在最后滚动多次时会出现重复,则它工作正常。我假设如果数据没有按时加载,我的用户可能会滚动多次
Future<List<DocumentSnapshot>> getMoreSearchDocuments(lastDocument) async{
querySnapshot = await Firestore.instance.collection('val').orderBy('dateCreated', descending:true)
.startAfterDocument(lastDocument).limit(documentLimit).getDocuments();
return querySnapshot.documents;
}
void _scrollListener() async{
if(_scrollController.offset >=
_scrollController.position.maxScrollExtent &&
!_scrollController.position.outOfRange) {
DocumentSnapshot lastDocument = widget.searchDocuments[widget.searchDocuments.length - 1];
setState((){
isLoading = true ;
print('You are at the end of the document');
});
await api.getMoreSearchDocuments(lastDocument)
.then((documentSnapshots){
setState(() {
widget.searchDocuments.addAll(documentSnapshots);
isLoading = false;
});
})
.catchError((e) {
print(e);
});
}
}
@override
void initState() {
_scrollController.addListener(_scrollListener);
super.initState();
}
SafeArea(
child: CustomScrollView(
controller: _scrollController,
slivers: <Widget>[
SliverAppBar(
title: Text('Rx finder'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.search),
onPressed: () =>
showSearch(context: context, delegate: SearchListings()),
....................
My Console Date which indicate the data is being fetched twice
I/flutter (25676): You are at the end of the document
I/flutter (25676): Second list
D/ViewRootImpl(25676): ViewPostImeInputStage processPointer 0
I/flutter (25676): You are at the end of the document
I/flutter (25676): Second list
解决方案
推荐阅读
- aws-cdk - aws-cdk 中的 CfnCloudFormationProduct 语法问题
- python - 如何从 JSON 文件中提取这些数据项?
- python - 从 Python 中的 Selenium 输出中获取 URL
- qt - Qt5-QML:如何在点击事件后处理按钮颜色和文本的变化
- amazon-web-services - EC2 Auto Scaling 实例在使用 CodeDeploy 时立即启动和终止
- nginx - Nginx - 有一个主代理,将请求代理到其他两个 Nginx
- github - GitHub GraphQL:获取特定存储库的所有分支
- r - 如何使用 xts 对象列表,如 R 中的 3d 数组?
- mongodb - Solr Mongo/DocDB 增量导入查询不起作用
- python - python中mysql的row_factory替代品