首页 > 解决方案 > 类“_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']);
                }
              },
            ))

这是我的 Firebase 存储: 在此处输入图像描述

我想检索 clID 但不知何故它不起作用。

这是错误信息。

在此处输入图像描述

太感谢了!!!

标签: firebaseflutterdartruntime-errorstream-builder

解决方案


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.


推荐阅读