Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 颤振:此查询中已存在条件[FieldPath([type]),==type]_Firebase_Flutter_Google Cloud Firestore - Fatal编程技术网

Firebase 颤振:此查询中已存在条件[FieldPath([type]),==type]

Firebase 颤振:此查询中已存在条件[FieldPath([type]),==type],firebase,flutter,google-cloud-firestore,Firebase,Flutter,Google Cloud Firestore,我有以下代码: Query _cardsQuery = FirebaseFirestore.instance.collection('Cards'); StreamSubscription _stream; String _selectedType; // This method is called after in initState() method void _getDataAndListen() { _stream?.cancel(); _stream=_car

我有以下代码:

Query _cardsQuery = FirebaseFirestore.instance.collection('Cards');

StreamSubscription _stream;

String _selectedType;


 // This method is called after in initState() method 
 void _getDataAndListen() {
   _stream?.cancel();
   _stream=_cardsQuery
          .orderBy('createdAt', descending: true)
          .snapshots()
          .listen((collection) => _fillData(collection));
  }
它很好用

但是,当我将新的
where
添加到
\u cardsQuery
时:

// This method is called after selecting the _selectedType
void _preparingQueryAndReListen() {
    if (_selectedType != null) {
      _cardsQuery = _cardsQuery.where('type', isEqualTo: _selectedType);
    }
    _getDataAndListen();
  }
出现以下错误:

条件。其中((列表项)=>equality.equals(条件, 项目( .isEmpty':此查询中已存在条件[FieldPath([type]),==,type]

这段代码中的错误在哪里

代码中使用的包是:


任何帮助,谢谢你

听起来你好像打了几次电话
\u preparingquery and dreen
。每次代码都会使用现有的
\u cardsQuery
并在
上添加一个条件键入
。由于查询在每个特定字段上只能包含一个条件,因此在第一次调用后,此调用将正确失败

基于共享代码的一个简单修复方法是每次调用
\u preparingqueryandresident
时从头开始重建查询:

  void _preparingQueryAndReListen() {
    _cardsQuery = FirebaseFirestore.instance.collection('Cards');
    if (_selectedType != null) {
      _cardsQuery = _cardsQuery.where('type', isEqualTo: _selectedType);
    }
    _getDataAndListen();
  }

从错误消息中可以看出,您向查询中添加了两次相同的条件。不过,我并没有立即在代码中看到这是如何发生的。是否有任何其他代码修改
\u cardsQuery
?这是唯一修改\u cardsQuery的代码,您已将\u cardsQuery替换为FirebaseFirestore.instance.collection('Cards'),它可以工作,但我丢失了变量是否为null的检查,我该怎么办,谢谢注意:第一次它没有给出此错误,而是第二次等等