Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.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 类型';列表<;动态>';不是类型为';收藏参考';属于';功能结果';_Firebase_Flutter_Dart_Google Cloud Firestore - Fatal编程技术网

Firebase 类型';列表<;动态>';不是类型为';收藏参考';属于';功能结果';

Firebase 类型';列表<;动态>';不是类型为';收藏参考';属于';功能结果';,firebase,flutter,dart,google-cloud-firestore,Firebase,Flutter,Dart,Google Cloud Firestore,下面是我希望从firestore获取PostTag对象列表的函数 class UsersDatabaseService { final String uid; UsersDatabaseService({this.uid}); final CollectionReference settingsCollection = Firestore.instance.collection('accountSettings'); static CollectionReference pos

下面是我希望从firestore获取
PostTag
对象列表的函数

class UsersDatabaseService {
  final String uid;

  UsersDatabaseService({this.uid});
  final CollectionReference settingsCollection = Firestore.instance.collection('accountSettings');
  static CollectionReference postTagListCollection= Firestore.instance.collection('postTagList');

...some code here...


static Future<List<PostTag>> getPostTags(String query)async{
    try {

      return  await postTagListCollection.where((tag) => tag.name.toLowerCase().contains(query.toLowerCase())).getDocuments()
          .then((snapshot) => yieldPostTags(snapshot));
    }catch(e){
      print(e.toString());
      return null;
    }
  }


  static List<PostTag> yieldPostTags(QuerySnapshot snapshot) {
    try {
      return snapshot.documents.map((doc) {
        print(doc.data['name']);
        return PostTag(
          category: doc.data['category'] ?? '',
          position: doc.data['position'] ?? 0,
          name: doc.data['name'] ?? ''
        );
      }).toList();
    }catch(e){
      print(e.toString());
      return null;
    }
  }

如何避免此错误

CollectionReference
是类
Query
的子类,由于方法
collection()
返回一个
CollectionReference
,因此您可以执行以下操作:

I/flutter (31837): 'package:cloud_firestore_platform_interface/src/method_channel/method_channel_query.dart': Failed assertion: line 119 pos 12: 'field is String || field is FieldPath': Supported [field] types are [String] and [FieldPath].
  static CollectionReference postTagListCollection= Firestore.instance.collection('postTagList');
问题在于:

      return  await postTagListCollection.where((tag) => tag.name.toLowerCase().contains(query.toLowerCase())).getDocuments()
该方法用于查询数据库,例如:

return await postTagListCollection.where("name", isEqualTo: "john").getDocuments()
您可以执行以下查询:

  Query where(
    dynamic field, {
    dynamic isEqualTo,
    dynamic isLessThan,
    dynamic isLessThanOrEqualTo,
    dynamic isGreaterThan,
    dynamic isGreaterThanOrEqualTo,
    dynamic arrayContains,
    List<dynamic> arrayContainsAny,
    List<dynamic> whereIn,
    bool isNull,
  }) {
querywhere(
动力场{
动态等质量,
动态无孤岛,
动态Islessthan或Qualto,
动态比,
动力比质量更好,
动态排列内容,
列表阵列内容,
其中,
布尔为空,
}) {

CollectionReference
是类
Query
的子类,由于方法
collection()
返回一个
CollectionReference
,因此您可以执行以下操作:

  static CollectionReference postTagListCollection= Firestore.instance.collection('postTagList');
问题在于:

      return  await postTagListCollection.where((tag) => tag.name.toLowerCase().contains(query.toLowerCase())).getDocuments()
该方法用于查询数据库,例如:

return await postTagListCollection.where("name", isEqualTo: "john").getDocuments()
您可以执行以下查询:

  Query where(
    dynamic field, {
    dynamic isEqualTo,
    dynamic isLessThan,
    dynamic isLessThanOrEqualTo,
    dynamic isGreaterThan,
    dynamic isGreaterThanOrEqualTo,
    dynamic arrayContains,
    List<dynamic> arrayContainsAny,
    List<dynamic> whereIn,
    bool isNull,
  }) {
querywhere(
动力场{
动态等质量,
动态无孤岛,
动态Islessthan或Qualto,
动态比,
动力比质量更好,
动态排列内容,
列表阵列内容,
其中,
布尔为空,
}) {

您是否通过打印(doc.data['name'])获得结果?否,t甚至没有到达该阶段您通过打印(doc.data['name'])获得结果?否,t甚至没有到达该阶段我看到我在删除.where并将其保留为
return wait postTagListCollection.getDocuments()后仍有错误
我仍然收到错误。此错误
类型“List”不是“function result”的类型“CollectionReference”的子类型
请删除静态关键字并使用final,同时注释此方法
yieldPostTags()
我发现我在那里犯了一个错误,但即使在删除.where并将其保留为
return wait postTagListCollection.getDocuments()之后
我仍然收到错误。此错误
类型'List'不是'function result'的'CollectionReference'类型的子类型。
删除静态关键字并使用final,同时注释此方法
yieldPostTags()