Firebase 尝试使用Flatter和Firestore过滤聊天信息
我正在尝试使用最新版本的Flatter Beta channel(1.23.0-18.1.pre)和cloud_firestore 0.14.3在我的聊天应用程序中创建阻止用户列表 以下是我的数据结构: 起初,我尝试了类似的方法(只是为了测试而硬编码),过滤我从Firestore查询的消息。Firebase不喜欢这样Firebase 尝试使用Flatter和Firestore过滤聊天信息,firebase,flutter,filter,google-cloud-firestore,Firebase,Flutter,Filter,Google Cloud Firestore,我正在尝试使用最新版本的Flatter Beta channel(1.23.0-18.1.pre)和cloud_firestore 0.14.3在我的聊天应用程序中创建阻止用户列表 以下是我的数据结构: 起初,我尝试了类似的方法(只是为了测试而硬编码),过滤我从Firestore查询的消息。Firebase不喜欢这样 query: firestore.collection('messages') .where('userId', whereNotIn: ['123456789',
query: firestore.collection('messages')
.where('userId', whereNotIn: ['123456789', '987654321'] )
.where('hashtag', isEqualTo: hashTag)
.orderBy('submittedAt', descending: true),
reverse: true,
我得到这个错误:
E/FLTFirestoreMsgCodec(24331):java.lang.IllegalArgumentException:查询无效。在字段“userId”上有一个不等式,其中filter(whereLessThan()、whereGreaterThan()等)必须位于字段“userId”中,因此必须将“userId”作为第一个orderBy()字段,但您的第一个orderBy()当前位于字段“submittedAt”中
在做了更多的阅读之后,通过隐藏消息在客户端进行过滤实际上更适合我的需要
不幸的是,我在兜圈子。我目前正在考虑将一个流映射到一个列表,然后执行如下操作:
if (message.userId is in the list) {
isBlocked = true;
} else {
isBlocked = false;
}
如果isBlocked为true,则过滤掉消息。我尝试硬编码的价值观,它的工作。顺便说一句,对于伪代码很抱歉,但是我偏离了很多次,现在我完全迷路了
我想知道这是不是正确的方法?任何建议都会被拒绝。我还尝试使用流中的未来列表,但我也无法让它工作
Future<Stream<List<BlockedUser>>> getBlockedIds() async {
Stream<List<BlockedUser>> list;
Stream<QuerySnapshot> snapshot = FirebaseFirestore.instance.collection('user').doc('id').collection('blocked').snapshots();
list = snapshot.map((query) => query.docs.map(
(doc) => BlockedUser(
id: doc.data()['id'])
).toList());
return list;
}
Future getBlockedIds()异步{
流列表;
流快照=FirebaseFirestore.instance.collection('user').doc('id').collection('blocked').snapshots();
list=snapshot.map((query)=>query.docs.map(
(doc)=>BlockedUser(
id:doc.data()['id'])
).toList());
退货清单;
}
因为我不知道该怎么处理这份清单,所以我无法让它发挥作用
谢谢大家