firebase - 类“_JsonDocumentSnapshot”没有实例方法“调用”。接收方:“_JsonDocumentSnapshot”实例尝试调用:call()
问题描述
我尝试使用 StreamBuilder 检索 Firebase 中的数据,但出现此错误。有谁知道如何解决这个问题?非常感谢您的帮助。
这是我的代码:
Container(
child: StreamBuilder(
stream: FirebaseFirestore.instance
.collection('orderInfo')
.doc(user.uid + 'order')
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Text('No data');
} else {
Map<String, dynamic> doc =
snapshot.data() as Map<String, dynamic>;
return Text(doc['clLady']);
}
},
))
我想检索 clID 但不知何故它不起作用。
这是错误信息。
太感谢了!!!
解决方案
Drop the parenthesis at the end of data like this
Map<String, dynamic> doc =
snapshot.data as Map<String, dynamic>;
snapshot.data is an attribute not a method or callable class, thats why you are getting an error.
推荐阅读
- c# - 知道函数何时完成处理
- c++ - 使用 0x 表示法打印地址
- android - Google Play 创建没有密钥库的应用签名密钥
- python - 在文本小部件上实时显示文本,同时在另一个文本上键入作为输入
- jboss - EAP 7.3: java.lang.ClassNotFoundException: # 授权给 Apache Software Foundation (ASF) 一个或多个 - 仅在独立模式下
- django - Django,查询过滤器按多个时间间隔重叠
- javascript - 使用 node.js 进行数据库克隆 sequelize
- sql - 将数据从一个 BigQuery 表插入另一个表返回 0 行分组依据
- latex - Rmarkdown:在pdf或word输出中修改Figure X标签为Figure SX
- php - Laravel MIN MAX GroupBy 来自集合