【问题标题】:Firebase firestore queries are not filtering data, even when using where in flutterFirebase firestore 查询不会过滤数据,即使在颤振中使用 where
【发布时间】:2021-03-08 01:24:37
【问题描述】:

我试图在我的颤振应用程序的 Firebase firestore 查询中使用where,但它显示集合中的所有数据而不过滤它。,这是我的代码:

  Widget buildingMessages() {
    print('message room id $roomID'); //The correct id is being printed here
    var theMessages = FirebaseFirestore.instance.collection('messages');
    theMessages.where('room_id',isEqualTo: roomID).orderBy('created', descending: true);
    return StreamBuilder<QuerySnapshot>(
      stream: theMessages.snapshots(),
      builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
        if (snapshot.hasError) {
          return Text('Something went wrong');
        }

        return new ListView(
          children: snapshot.data.docs.map((DocumentSnapshot document) {
//....

【问题讨论】:

    标签: android firebase flutter stream-builder


    【解决方案1】:

    问题出在stream: theMessages.snapshots()。您正在引用 theMessages。而且您没有使用 where 子句。用你的 where 子句扩展它。喜欢

    stream: theMessages.snapshots().where(
                      'room_id',isEqualTo: roomID).orderBy('created', descending: true);
    

    编辑:或将其初始化为

    var theMessages = FirebaseFirestore.instance.collection('messages').
                where('room_id',isEqualTo: roomID).orderBy('created', descending: true);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-22
      • 2021-11-29
      • 2020-03-15
      • 1970-01-01
      • 1970-01-01
      • 2021-06-19
      相关资源
      最近更新 更多