【发布时间】:2020-11-16 06:09:31
【问题描述】:
我正在尝试从与 streambuilder 不同的 firestore 集合中查询文档字段。现在,使用流构建器,我可以查询我需要的一个文档,但是我不知道如何在同一个流构建器中查询另一个集合。我考虑过使用另一个类中的全局变量,我已经在其中查询了我想要的文档,但这似乎不起作用。
这是流生成器
Container(
height: MediaQuery.of(context).size.height,
margin: EdgeInsets.only(top: 0),
padding: EdgeInsets.only(top: 0),
child: StreamBuilder(
stream: Firestore.instance
.collection('Tournaments')
.document('Fortnite Tournaments')
.collection('Fortnite Tourneys')
.document(docID)
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return new Text("Loading");
}
var tourneyDetails = snapshot.data;
return ListView(
children: <Widget>[
..........
我要查询的集合称为“用户”
为什么我需要查询不同集合中的字段是因为我正在编写一个需要两个字段的 if 语句
if (int.parse("Field_i_am_trying_to_get_from_another_collection") > int.parse(tourneyDetails[ 'tourneycost']))
print('You have the money');
else {
print('You're broke');
}
当点击凸起的按钮时,该条件将被执行。本质上,我的问题是我目前不确定如何从其他集合中查询数据。
不确定我是否解释得很好,但如果您需要更多上下文或代码,请发表评论,谢谢。
【问题讨论】:
-
你可以嵌套一个流构建器来查询 ListView 中的第二个集合
标签: flutter dart google-cloud-firestore