我正在學習 firebase 并嘗試創建一個聊天應用程式......
我點擊用戶串列來檢查他的聊天室是否已經用 l 創建了
- 專案清單
登錄用戶與否....為此,我創建了一個未來功能...但顯示錯誤..看起來它拒絕使用帶有 where 子句的 [ 斷路器 ....如果是這樣,那么如何獲取地圖鍵的值...一般我使用 varmap['key']。
Future<ChatroomModel?> getchatroom(UserModel targetuser) async {
ChatroomModel? temp;
QuerySnapshot querysnapshot = await FirebaseFirestore.instance
.collection('chatrooms')
.where("participants[${widget.usermodel.userid}]", isEqualTo: true)
.where("participants[${targetuser.userid}]", isEqualTo: true)
.get();
if (querysnapshot.docs.length > 0) {
print("already exists");
} else {
print("Created new one");
}
return temp;
}
這是我的聊天室模型
class ChatroomModel
{
String? chatroomid;
Map<String,dynamic>? participants;//{'xdsfsdf':true, 'afdafd':true}
String? lastmessage;
ChatroomModel({this.chatroomid, this.participants,this.lastmessage});
ChatroomModel.fromMap(Map<String, dynamic> map) {
chatroomid=map['chatroomid'];
participants=map['participants'];
lastmessage=map['lastmessage'];
}
Map<String,dynamic> toMap()
{
return {
'chatroomid':chatroomid,
'participants':participants,
'lastmessage':lastmessage,
};
}
}
出現以下錯誤
[ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: 'package:cloud_firestore_platform_interface/src/field_path.dart': Failed assertion: line 50 pos 16: '!path.contains('[')': Paths must not contain '~', '*', '/', '[', or ']'.
uj5u.com熱心網友回復:
嘗試這個:
QuerySnapshot querysnapshot = await FirebaseFirestore.instance
.collection('chatrooms')
.where("participants." widget.usermodel.userid, isEqualTo: true)
.where("participants." targetuser.userid, isEqualTo: true)
.get();
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/533171.html
標籤:扑镖
上一篇:顫動中的動態進度條