Firestore查询在StreamBuilder内部获得弹力中的其他信息
我的代码有问题。如果语句,我仅在StreamBuilder中收到我的第一个查询的数据。我需要使用循环吗???
使用Listenstream,我将收到例如4个结果。结果中有2个具有“ kategorien” =“ keine'”字段中的值。我需要完成这两个字段,以在我的程序中显示来自if streambuilder IF语句中查询的结果。我希望我能解释一下我的目标。
问题是,我仅收到数据库中第一个条目的第一个“ kategorie”。
有人可以帮我吗?
这是我的代码:
StreamBuilder<QuerySnapshot>(
stream: listenStream,
builder: (context,snapshot){
if (snapshot.hasError) {
return Text('Something went wrong');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return Text("Loading");
}
return ListView.builder(
itemCount:snapshot.data?.docs.length,
itemBuilder: (context,index){
String? falscheKat = snapshot.data?.docs[index]['kategorie'].toString();
if(falscheKat=='Keine')
{
FirebaseFirestore.instance.collection('artikel').where('item', isEqualTo: snapshot.data?.docs[index]['item'].toString())
.get().then((value) {
neueKat = value.docs[0].get("item");
});
}
return ListTile(
title: Text(snapshot.data?.docs[index]['item']),
subtitle: Text(neueKat.toString()),
);
},
);
})
在这里我的Firestore查询Listenstream:
final Stream<QuerySnapshot> listenStream = FirebaseFirestore.instance
.collection('listen1')
.doc('zuhause')
.collection('artikel').snapshots();
i have problems with my code. i receive only the data of my first query inside the streambuilder if statement. do i need to use a loop ???
With listenStream i receive for example 4 results. 2 of the results have the value in field 'kategorien' = 'Keine'. These 2 fields i need to complete to show in my programm with the results from the query inside the if statement of the streambuilder. i hope i explained a little to understand my targets.
The problem is, that i receive only the first 'kategorie' for the first entry in the database.
can someone help my please?
Here is my code:
StreamBuilder<QuerySnapshot>(
stream: listenStream,
builder: (context,snapshot){
if (snapshot.hasError) {
return Text('Something went wrong');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return Text("Loading");
}
return ListView.builder(
itemCount:snapshot.data?.docs.length,
itemBuilder: (context,index){
String? falscheKat = snapshot.data?.docs[index]['kategorie'].toString();
if(falscheKat=='Keine')
{
FirebaseFirestore.instance.collection('artikel').where('item', isEqualTo: snapshot.data?.docs[index]['item'].toString())
.get().then((value) {
neueKat = value.docs[0].get("item");
});
}
return ListTile(
title: Text(snapshot.data?.docs[index]['item']),
subtitle: Text(neueKat.toString()),
);
},
);
})
and here my Firestore query listenStream:
final Stream<QuerySnapshot> listenStream = FirebaseFirestore.instance
.collection('listen1')
.doc('zuhause')
.collection('artikel').snapshots();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于第二firestore查询,请使用另一个
streambuilder
。Use another
StreamBuilder
for the second Firestore query.