简体   繁体   English

Flutter - 没有为类“DocumentReference”定义方法“where” <Map<String, dynamic> &gt;&#39;

[英]Flutter - The method 'where' isn't defined for the class 'DocumentReference<Map<String, dynamic>>'

I tried to initialize the 'where' so that it will read from the firestore, I want to read all the documents that have the (number of users) equal to 20 from the document and then display them on the screen.我试图初始化'where'以便它从firestore读取,我想从文档中读取(用户数)等于20的所有文档,然后将它们显示在屏幕上。 but it gives me the error mentioned above.但它给了我上面提到的错误。 how can I implement the where statement without getting this error?如何在不出现此错误的情况下实现 where 语句?

class _communityFinderState extends State<communityFinder> {

  late QuerySnapshot communityFinder;
  FirebaseFirestore _firestore = FirebaseFirestore.instance;
  bool _loading = false;

  Future getCommunities()async{
    setState(() {
      _loading = true;
    });
    communityFinder = await _firestore.collection('Community').doc('com').where("numberOfMembers",isEqualTo: 20).get();

    setState(() {
      _loading = false;
    });
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getCommunities();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _loading ? Center(child: CircularProgressIndicator()) : ListView.builder(
          shrinkWrap: true,
          itemCount: communityFinder.docs.length,
          itemBuilder: (BuildContext context, int index) {

            return Column(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [

                SizedBox(
                  height: MediaQuery.of(context).size.width *0.05,
                ),

                InkWell(
                  child: Container(
                    width: MediaQuery.of(context).size.width *0.80,
                    height: MediaQuery.of(context).size.width *0.15,

                    decoration: BoxDecoration(
                      border: Border.all(
                        color: Colors.blue,
                      ),
                      color: Colors.black12,
                    ),

                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [

                        Row(
                          children: [

                            SizedBox(
                              width: MediaQuery.of(context).size.width *0.04,
                            ),

                            Text(
                              communityFinder.docs[index].get("CommunityName").toString(),
                              style: TextStyle(
                                color: Colors.black,
                                fontSize: MediaQuery.of(context).size.width *0.05,
                              ),
                            ),

                          ],
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            );
          }
      ),
    );
  }
}

You need to remove the .doc(DocID): _firestore.collection('Community').where("numberOfMembers",isEqualTo: 20).get()您需要删除 .doc(DocID): _firestore.collection('Community').where("numberOfMembers",isEqualTo: 20).get()

With .doc(DocID) you select only one document so it doesn't make sense in this case使用 .doc(DocID) 您只选择一个文档,因此在这种情况下没有意义

DocumentReference returned by doc() doesn't have a method called where , but CollectionReference returned by collection() does. doc()返回的DocumentReference没有名为where的方法,但collection()返回的CollectionReference有。 You probably want to remove the doc() call between those.您可能希望删除它们之间的doc()调用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter FireStore:未为类型“DocumentReference”定义方法“where” - Flutter FireStore: The method 'where' isn't defined for the type 'DocumentReference' “没有为类型文档引用定义的方法”? - “ the method where isn't defined for the type documentreference”? 未为 class 'Map 定义运算符'[]'<string, dynamic> 功能()'</string,> - The operator '[]' isn't defined for the class 'Map<String, dynamic> Function()' 该方法未为 class 定义 - Flutter - The method isn't defined for the class - Flutter 类颤振中未定义方法“SignInWithTwitter” - The method 'SignInWithTwitter isn't defined in the class flutter 如何解决“返回类型&#39;DocumentReference()&#39;不是&#39;DocumentReference()&#39;,由方法”错误定义? - How to solve “The return type 'DocumentReference ()' isn't a 'DocumentReference ()', as defined by the method” error? Flutter/cloud_firestore:未为 Map 类型定义运算符“[]”<string, dynamic> 功能()</string,> - Flutter/cloud_firestore: The operator '[]' isn't defined for the type Map <String, dynamic> Function() Flutter:没有为 class“列表”定义吸气剂“answers” <map<string, object> >' </map<string,> - Flutter: The getter 'answers' isn't defined for the class 'List<Map<String, Object>>' 没有为“DocumentReference”类型定义获取器“documentID” - The getter 'documentID' isn't defined for the type 'DocumentReference' flutter:未为 class 未来定义运算符“[]”<map> '</map> - flutter: operator '[]' isn't defined for the class 'Future<Map>'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM