[英]how to return array as stream in flutter firestore?
I'm trying to return a post array from firestore as a stream in flutter.我试图从firestore返回一个post数组作为flutter中的stream。
return Scaffold(
body: StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection('groups')
.doc(groupId)
.snapshots(),
builder: (_, snapshot) {
if (snapshot.hasData) {
final docs = snapshot.data!.docs;
return ListView.builder(
itemCount: querySnapshot.docs.length,
itemBuilder: ((context, i) {
final docdata = docs[i].data();
return ListTile();
}));
} else {
return Text('wait');
}
;
},
),
);
Query returns a single document ie a stream with DocumentSnapshot type instead of QuerySnapshot
.查询返回单个文档,即 stream 与DocumentSnapshot类型而不是
QuerySnapshot
。
StreamBuilder<DocumentSnapshot>(
stream: FirebaseFirestore.instance
.collection('groups')
.doc(groupId)
.snapshots(),
builder: (_, snapshot) {
...
},
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.