简体   繁体   English

当我尝试在 listview.buider 中使用 snapshot.data.docs.length 时出现此错误:getter 'docs' 没有为类型 'Object' 定义

[英]i got this error when i am trying to use snapshot.data.docs.length in listview.buider: The getter 'docs' isn't defined for the type 'Object'

I am trying to fetch data from firebase to list all the documents in a listview builder the code is still not completed in term of displaying the database filed in the code.我正在尝试从 firebase 获取数据以列出列表视图构建器中的所有文档,但在显示代码中归档的数据库方面,代码仍未完成。 this is the error: The getter 'docs' isn't defined for the type 'Object'这是错误:没有为“对象”类型定义吸气剂“文档”

Container(
              child: StreamBuilder<Object>(
                  stream: _firestore
                      .collection('Patient')
                      .doc(_auth.currentUser.email)
                      .collection("Diabetes")
                      .snapshots(),
                  builder: (context, snapshot) {
                    if (snapshot.hasData) {
                      return ListView.builder(
                          reverse: true,
                          shrinkWrap: true,
                          itemCount:
                              snapshot.data.docs.length, // here is the error "docs"
                          itemBuilder: (context, index) {
                            DocumentSnapshot documentSnapshot =
                                snapshot.data.docs[index]; // also another error "docs"
                            return Container();
                          });
                    }
                    return Center(
                      child: CircularProgressIndicator(),
                    );
                  }),
            )

You should replace snapshot.data.docs.length with snapshot.data.length您应该将 snapshot.data.docs.length 替换为 snapshot.data.length

 Container(
    child: StreamBuilder<Object>(
       stream: _firestore
         .collection('Patient')
         .doc(_auth.currentUser.email)
         .collection("Diabetes")
         .snapshots(),
       builder: (context, snapshot) {
         if (snapshot.hasData) {
           return ListView.builder(
               reverse: true,
               shrinkWrap: true,
               itemCount: snapshot.data.length,
               itemBuilder: (context, index) {
                 DocumentSnapshot documentSnapshot = snapshot.data[index];
                 return Container();
               });
        }
        return Center(
         child: CircularProgressIndicator(),
        );
     }),
    )

I solved the problem by replacing StreamBuilder<Object> with StreamBuilder<QuerySnapshot> .我通过用StreamBuilder<QuerySnapshot>替换StreamBuilder<Object>解决了这个问题。 by default the StreamBuilder comes in this form StreamBuilder<Object>默认情况下,StreamBuilder 采用这种形式StreamBuilder<Object>

暂无
暂无

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

相关问题 snapshot.data.docs.length 不适用于 flutter - snapshot.data.docs.length not working on flutter 没有为“AsyncSnapshot”类型定义吸气剂“文档”<object?> '</object?> - The getter 'docs' isn't defined for the type 'AsyncSnapshot<Object?>' 没有为类型“DocumentSnapshot”定义吸气剂“文档” <Map<String, dynamic> &gt; - The getter 'docs' isn't defined for the type 'DocumentSnapshot<Map<String, dynamic>> 如何解决“没有为类型 'DocumentSnapshot' 定义 getter 'docs'。”? - How to fix “The getter 'docs' isn't defined for the type 'DocumentSnapshot'.”? 错误:没有为 class“对象”定义吸气剂“文档”。 - “对象”来自“飞镖:核心” - Error: The getter 'docs' isn't defined for the class 'Object'. - 'Object' is from 'dart:core' 我的错误没有为“LoginResult”类型定义 getter“token”。 尝试导入定义“令牌”的库, - I'am error The getter 'token' isn't defined for the type 'LoginResult'. Try importing the library that defines 'token', 没有为“Object”类型定义 getter“length”。 // 运算符 &#39;[]&#39; 不是为类型 &#39;Object&#39; 定义的 - The getter 'length' isn't defined for the type 'Object'. // The operator '[]' isn't defined for the type 'Object' 当我按照文档尝试将我的 Android Studio 连接到 Firebase 时出现错误 - Getting error when I am trying to connect my Android Studio to Firebase following the docs 没有为“对象”类型定义 getter“文档”- Flutter 错误 - The getter 'documents' isn't defined for the type 'Object' - Flutter Error 没有为类型“List”定义 getter“displayName”<UserModal> &#39;。 但我已经定义了它。 有什么我做错了吗? - The getter 'displayName' isn't defined for the type 'List<UserModal>'. But I have defined it. Is there something I am doing wrong?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM