【发布时间】:2021-03-06 04:37:26
【问题描述】:
我正在尝试获取我的数据信息流。由于某种原因,我做不到。它甚至没有打印出我的内部打印语句“print(“Inside snapshot”)”。
请查看我的代码并告诉我如何解决此问题。 我期待听到您的所有意见和想法。在此先感谢您。
终端消息
W/DynamiteModule( 3822): Local module descriptor class for providerinstaller not found.
I/DynamiteModule( 3822): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller( 3822): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
I/flutter ( 3822): Inside _messageList
型号
class Conversation {
final DateTime date;
final String message;
final String sendby;
Conversation({this.date, this.message, this.sendby});
}
屏幕代码
return StreamBuilder<List<Conversation>>(
stream: User_DatabaseService(uid: uid).chatroomMesssages,
builder: (context, snapshot) {
List<Conversation> messageList = snapshot.data ?? [];
messageList.forEach((message) {
print("${message.date} ${message.message} ${message.sendby}");
});
//-----
}
数据库代码
// collection reference
final CollectionReference chatroomCollection =
FirebaseFirestore.instance.collection('chatrooms');
// all conversation
List<Conversation> _messageList(QuerySnapshot snapshot) {
print("Inside _messageList");
return snapshot.docs.map((doc) {
print("Inside snapshot");
final dataInfo = doc.data();
print(dataInfo['date']);
return Conversation(
date: dataInfo['date'] ?? null,
sendby: dataInfo['sendBy'] ?? null,
message: dataInfo['message'] ?? null,
);
}).toList();
}
//Get all conversation
Stream<List<Conversation>> get chatroomMesssages {
//print('in allUserData');
print("Inside getChatroomMesssages");
return userCollection
.doc('devil@yahoo.com_punreach@yahoo.com')
.collection("chats")
.snapshots()
.map(_messageList);
}
【问题讨论】:
-
是否有任何错误,或任何其他相关输出?
userCollection是什么? -
它应该给我子集合数据。但它没有
-
哦,是的,我用错了名字。
-
写下你的答案!我会给你我的积分
-
我刚刚做到了!很高兴能帮上忙。
标签: flutter google-cloud-firestore stream state-management