Firebase 类型“Query”不是类型“CollectionReference”的子类型

Firebase 类型“Query”不是类型“CollectionReference”的子类型,firebase,flutter,google-cloud-firestore,Firebase,Flutter,Google Cloud Firestore,我试图按发布日期对数据进行排序,但得到的“type”Query不是“CollectionReference”类型的子类型。“我尝试过搜索解决方案,但都是徒劳的!”! 我的代码: Am获取的“类型”查询不是“CollectionReference”类型的子类型更改此设置 final CollectionReference wordsCollection = Firestore.instance.collection('words').orderBy('date_posted'); 进入这个

我试图按发布日期对数据进行排序,但得到的“type”Query不是“CollectionReference”类型的子类型。“我尝试过搜索解决方案,但都是徒劳的!”! 我的代码:

Am获取的“类型”查询不是“CollectionReference”类型的子类型更改此设置

 final CollectionReference wordsCollection =
  Firestore.instance.collection('words').orderBy('date_posted');
进入这个

    final Query wordsCollection =
  Firestore.instance.collection('words').orderBy('date_posted');
改变这个

 final CollectionReference wordsCollection =
  Firestore.instance.collection('words').orderBy('date_posted');
进入这个

    final Query wordsCollection =
  Firestore.instance.collection('words').orderBy('date_posted');

CollectionReference是Query的一个子类。您可以将CollectionReference分配给查询,但不能反过来分配。您必须按照以下方式重新构造代码:

  // This refers to just the collection "words", no implied ordering
  final CollectionReference wordsCollection = Firestore.instance.collection('words');

  Stream<List<Words>> get words {
    // This forces an ordering on the documents in the collection
    return wordsCollection.orderBy('date_posted').snapshots().map(_wordsFromSnapShots);
  }

CollectionReference是Query的一个子类。您可以将CollectionReference分配给查询,但不能反过来分配。您必须按照以下方式重新构造代码:

  // This refers to just the collection "words", no implied ordering
  final CollectionReference wordsCollection = Firestore.instance.collection('words');

  Stream<List<Words>> get words {
    // This forces an ordering on the documents in the collection
    return wordsCollection.orderBy('date_posted').snapshots().map(_wordsFromSnapShots);
  }

我试过了,但现在它带来了这个错误“type”Query不是“CollectionReferenceI”类型的子类型我试过了,但现在它带来了这个错误“type”Query不是“CollectionReferenceI”类型的子类型如果你觉得这个答案有用,通常,堆栈溢出会向上投票并使用答案左侧的按钮将其标记为正确。如果您认为此答案有用,则堆栈溢出会向上投票并使用答案左侧的按钮将其标记为正确。