我正在将 Firebase 中的数据访问到流构建器中,如下所示:
new StreamBuilder(
stream: Firestore.instance.collection('posts').snapshots(),
builder: (context, snapshot) {
print(snapshot.data.documents[0].toString());
}
)
我已经尝试过使用和不使用 toString()
但没有运气。控制台总是显示“DocumentSnapshot”实例
如何正确查看数据对象内的所有键值?
最佳答案
根据https://pub.dartlang.org/documentation/cloud_firestore/latest/cloud_firestore/DocumentSnapshot-class.html ,您应该调用 data
属性来获取 Map
对象,该对象已实现 toString()
方法,以便将自身打印为可读字符串。
print(snapshot.data.documents[0].data);
print(snapshot.data.documents[0].data.toString()); // or explicitly
关于dart - 如何正确查看Flutter中的所有对象数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53466794/