如何转换类型' Future< dynamic>'不是类型的子类型吗?
我想从StreamBuilder中获取Firebase的数据。如何将未来转化为流。
以下是我的代码。
getData() async {
var db = FirebaseFirestore.instance;
await db.collection('categories').doc(value).get().then((DocumentSnapshot doc) {
var listSubCol = doc["categoryCollection"];
listSubCol.forEach((id) {
db.collection('categories').doc(value).collection(id).get().then((snapshot) {
snapshot.docs.forEach((element) {
items.add(element.data());
});
});
return items;
});
});
return items;
}
StreamBuilder(
stream: getData(),
builder: (BuildContext context,snapshot){
print('snap: ${items.length}');
if(!snapshot.hasData){
return Center(
child: CircularProgressIndicator(),
);
}else{
return Container(
child: ListView.builder(
shrinkWrap: true,
itemCount: items.length,
itemBuilder: (context, int index){
return Text(items[index]['categoryName']);
},
),
);
}
}
),
任何人都可以在这个问题上帮我吗?
I want to get the data from Firebase in streambuilder. How to convert the Future into Stream.
Below is my code.
getData() async {
var db = FirebaseFirestore.instance;
await db.collection('categories').doc(value).get().then((DocumentSnapshot doc) {
var listSubCol = doc["categoryCollection"];
listSubCol.forEach((id) {
db.collection('categories').doc(value).collection(id).get().then((snapshot) {
snapshot.docs.forEach((element) {
items.add(element.data());
});
});
return items;
});
});
return items;
}
StreamBuilder(
stream: getData(),
builder: (BuildContext context,snapshot){
print('snap: ${items.length}');
if(!snapshot.hasData){
return Center(
child: CircularProgressIndicator(),
);
}else{
return Container(
child: ListView.builder(
shrinkWrap: true,
itemCount: items.length,
itemBuilder: (context, int index){
return Text(items[index]['categoryName']);
},
),
);
}
}
),
can anyone please help me on this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论