flutter - Flutter:访问 GridView Stream 元素内的未来值
问题描述
我有一个基于 Firestore 流的 Flutter GridView。对于 Grid 的每个元素,我希望通过访问 Firebase 文档使用 Future 值检查某些状态。代码如下
...
StreamBuilder<QuerySnapshot> {
stream: db.collection('coll1').orderBy('field1').snapshots(),
builder: : (context, snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
} else {
return GridView.count(
crossAxisCount: 2,
children: snapshot.data!.docs.map((doc) {
//
// here is where I would like the future value
bool exists = checkIfExists(doc.id);
//
// and use the value in the card below
//
return Card(
child: ListTile(
title: Text(doc.get('field1')),
onTap: () {...},
),
);
}).toList());
}
},
);
.....
Future<bool> checkIfExists(id) async {
...
DocumentSnapshot doc = await db.collection('coll2').doc(id).snapshot();
return doc.exists ? true : false
}
谢谢
解决方案
推荐阅读
- java - SpringBootApplication 中的字段 jdbcTemplate 需要找不到类型为“org.springframework.jdbc.core.JdbcTemplate”的 bean
- process - 合并 2 个进程 -> 父母收养孩子
- python - 逐行创建和附加 CSV
- r - 保留基于另一列重复的某些列
- woocommerce - 将重量属性移动到 WooCommerce 产品页面的底部?
- php - SELECT 元素的未定义索引错误,但其格式与表单中的其他选择元素相同
- java - Discord bot JDA 不起作用,由 java.lang.ClassNotFoundException 引起
- javascript - 如何检测何时使用 jQuery 按下了删除键?
- java - Maven 没有在 Windows JDK 11 上运行,它说 JAVA_HOME 没有设置
- python - 如何在谷歌驱动API python中组合查询字符串