gpt4 book ai didi

android - 错误状态 : field does not exist within the DocumentSnapshotPlatform . 它表明 getter 是在 null 上调用的

转载 作者:行者123 更新时间:2023-12-05 00:15:40 24 4
gpt4 key购买 nike

导致错误的相关小部件是流生成器。我已经在 github 中给出了项目存储库的链接。

Widget build(BuildContext context) {
return StreamBuilder(
stream: FirebaseFirestore.instance
.collection("/chats/2DGQmBssJ4sU6MVJZYc0/messages")
.orderBy('createdAt', descending: true)
.snapshots(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting)
Center(child: CircularProgressIndicator());
final documents = snapshot.data.documents;
return ListView.builder(
reverse: true,
itemCount: documents.length,
itemBuilder: (context, index) {
return MessageBubble(
documents[index]['text'],
documents[index]['userID'] == user.uid,
documents[index]['userID'],
documents[index]['imageurl']);
},
);
},
);

}}

Github link of the project

最佳答案

尝试以下操作:

 if (snapshot.connectionState == ConnectionState.waiting)
Center(child: CircularProgressIndicator());
else if(snapshot.connectionState == ConnectionState.active){
final documents = snapshot.data.documents;
return ListView.builder(
reverse: true,
itemCount: docs.length,
itemBuilder: (context, index) {
return MessageBubble(
docs[index]['text'],
docs[index]['userID'] == user.uid,
docs[index]['userID'],
docs[index]['imageurl']);
},
);
},
},
);

当连接状态为 Activity 状态且数据非空时,则检索数据。另外,请使用 docs,因为您似乎正在使用新版本的 Firestore。

文档成为文档

关于android - 错误状态 : field does not exist within the DocumentSnapshotPlatform . 它表明 getter 是在 null 上调用的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65069871/

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