firebase - StreamBuilder 更新颤振后返回错误
问题描述
在更新颤振之后,我在 StreamBuilder 中遇到了一个问题。标有 ** 的行返回错误。我试图通过添加空检查(!)来纠正它,但它返回:
没有为“对象”类型定义运算符“[]”。
我该如何解决?
此外,是否有更优雅的方式(也就是没有 StreamBuilder)来拍摄快照/流?例如,我注意到以下代码行是有效的:
FirebaseFirestore.instance.collection("campdata").doc(docId).snapshots();
但是,我不知道如何进一步开发它,以便它从 firebase 返回可读数据。
非常感谢
strem_builder_matcheduser(){
return StreamBuilder(
stream: firestore.collection("Requests").doc(matched_user_mail).snapshots(),
builder: (context, snapshot) {
if (snapshot.hasData) {
final messages = snapshot.data;
matched_user_connectionstatus = **messages['status of connection']**;
}
if(matched_user_connectionstatus=="offline"){
try{
}catch(e){}
return SizedBox();
}
else
return Text("");
}
);
}
解决方案
将其更改为:
matched_user_connectionstatus = messages.get('status of connection');
或这个:
final messages = snapshot.data() as Map<String, dynamic>;
matched_user_connectionstatus = messages['status of connection'];
推荐阅读
- xamarin.forms - 在特定点替换 SK Canvas 上已绘制的位图
- go - Go HTTP 库刚导入时出现错误,discordgo 也是如此
- git - 审阅者可以将他们的签名添加到特定的 git 提交吗?
- r - 线性插值以填充不大于 2 天的间隙的 NoData
- apache-storm - 如何获取与 apachestorm 中的每个执行程序相关联的任务列表?
- python-3.x - 将 Pandas DataFrame 中的值替换为来自同一 DataFrame 的唯一值
- html - span 标签内的垂直居中文本
- c# - 将行动态添加到 ListView 中的网格
- deep-learning - 如何为多维目标定义自定义损失函数
- css - 单击后保持角度材质垫波纹动画