我目前正在将Cloud Firestore与Streambuilder小部件一起使用,以便使用Firestore文档填充ListView小部件.
new StreamBuilder<QuerySnapshot>(
stream: Firestore.instance.collection('videos').limit(10).snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) return new Center(
child: new CircularProgressIndicator(),
);
return new ListView(
children: snapshot.data.documents.map((DocumentSnapshot document) {
new Card(child: ...)
}).toList(),
);
},
);
Run Code Online (Sandbox Code Playgroud)
然而,此设置仅允许查询前x个结果(在这种情况下x = 10),其中x是固定数字,用户希望看到的卡片小部件的数量迟早会被超出或超过向下滚动.
现在是否可以查询前x个结果,并在用户点击滚动阈值后查询来自Cloud Firestore的下一个x + 10结果,依此类推?
这将允许动态列表长度,这也将有利于Firestore数据消耗.