list - 有没有办法在flutter firebase中查询文档中的整个列表?
问题描述
我正在构建一个具有聊天功能的应用程序,现在我正在尝试显示所有最后的历史票证。我有一个存储所有当前用户房间聊天的用户数据库,我将它提取到 List currentUserRoomList。
// Getting a stream of the chat
getChatStream() {
return chatRef
.doc(currentUserRoomList.first) // << here
.collection('messageId')
.orderBy('timeStamp', descending: true)
.limit(1)
.snapshots();
}
// Build the story tickets here
buildStoryTickets() {
return StreamBuilder(
stream: getChatStream(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return loading();
}
List<ChatHistory> tickets = [];
snapshot.data.docs.forEach((doc) {
ChatHistory ticket = ChatHistory(
id: doc.data()['id'],
otherUserId: doc.data()['otherId'],
message: doc.data()['message'],
photoUrl: currentUserId == doc.data()['id']
? doc.data()['photos'][1]
: doc.data()['photos'][0],
displayName: currentUserId == doc.data()['id']
? doc.data()['names'][1]
: doc.data()['names'][0],
rid: doc.data()['rid'],
timeStamp: doc.data()['timeStamp'],
);
tickets.add(ticket);
});
return ListView(children: tickets);
},
);
chatRef 来自另一个页面。->
final chatRef = FirebaseFirestore.instance.collection('chatrooms');
我在 chatRef 中有应用程序中的所有房间 ID。我的问题是 getChatStream(),当我只给它一个值时它工作(例如:.doc(currentUserRoomList.first)),但我正在尝试为 currentUserRoomList 中的所有值构建历史票证,我正在努力解决这个问题. 提前致谢!
解决方案
推荐阅读
- if-statement - ifelse 在我想要 0 时给我 NA
- flutter - 如何仅隐藏 TextField 中的某些文本
- gradle - 任务计数与 gradle build 命令输出中显示的可操作任务之间有什么关系?
- amazon-web-services - 如何使用 Power Shell 为 AWS IAM 策略设置标签
- firebase - Firebase 电话验证 OTP 某些号码已验证,其他号码在 PHONE 中收到 OTP 后未验证,当我将颤振应用程序上传到 Play 商店时,
- c# - 从 appsettings 配置部分读取值并在预定义的位置注入值
- php - 语法错误,C:\xamppp\htdocs\ecommerce\include\function.php 中的意外 '$path' (T_VARIABLE) 第 39 行
- javascript - 获取具有动态生成 ID 的元素
- assembly - 有没有办法从 C64 的 Kick Assembler 中的宏访问全局常量
- html - 如何对齐导航栏上的所有元素?好像有点移位