gpt4 book ai didi

firebase - 关闭 : () => Map 来自函数 'data' :

转载 作者:行者123 更新时间:2023-12-03 04:35:56 24 4
gpt4 key购买 nike

所以我试图从 firestore 流式传输数据,但是在打印数据时我得到:
I/flutter (8356):闭包:() => Map from Function 'data':.
我正在使用此代码来获取数据:

 void messagesStream() async {
Stream collectionStream = _firestore.collection('messages').snapshots();
await for (var snapshot in collectionStream) {
for (var message in snapshot.docs) {
print(message.data());
}
}
当新数据添加到消息集合时,我会收到 Closure 消息,因此它正在与数据库进行交互。
我想要的是打印出集合中新文档的内容。
任何帮助表示赞赏。

最佳答案

这不是您应该迭代 Stream 结果的方式。如果你有一个 Stream 并且你想处理它的结果,你应该使用 listen()异步接收结果。

Stream collectionStream = _firestore.collection('messages').snapshots();
collectionStream.listen((QuerySnapshot querySnapshot) {
querySnapshot.documents.forEach((document) => print(document.data()));
}
另见: Firestore collection query as stream in flutter
您可能还想查看 documentation了解如何在 Flutter 中查询 Firestore。

关于firebase - 关闭 : () => Map<String, 动态> 来自函数 'data' :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64122333/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com