getter“文档”;没有为类型“Object”定义;

发布于 2025-01-16 10:09:23 字数 1880 浏览 5 评论 0 原文

我在 Firebase 中有一个名为 status 的集合。我正在尝试从这里提取数据。但是我收到这个错误。

我尝试了一些解决方案,但仍然遇到相同的错误。 例如;我使用 StreamBuilder' 定义 getter 'documents'。”。另一个例子,我使用了 docs 而不是 word 文档。我再次遇到同样的错误。最后,当我删除文档或文档一词时,出现如下错误。“没有为类型‘QuerySnapshot’定义 getter 'lenght'。”

我的代码:

class Home extends StatefulWidget {
  const Home({Key? key}) : super(key: key);
  @override
  State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
      final FirebaseFirestore _database = FirebaseFirestore.instance;
      final StatusService _statusService = StatusService();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.orange,
        automaticallyImplyLeading: false,
        title: Center(
          child: Text(
            'Home',
            style: TextStyle(color: Colors.white),
          ),
        ),
      ),
      body: StreamBuilder(
        stream: _statusService.getStatus(),
        builder: (BuildContext context, snaphot){
          return !snaphot.hasData
              ? CircularProgressIndicator()
              : ListView.builder(
               itemCount: snaphot.data?.documents.lenght, //Error in here "documents"
              itemBuilder: (context, index){
                DocumentSnapshot mypost = snaphot.data?.documents[index]; // also another error in here " documents"
                return Padding(
                  padding: const EdgeInsets.all(12.0),
                  child: Container(
                    child: Column(children: [
                      Text("${mypost['status']}")
                    ],),
                  ),
                );
          }
          );
        },
      ) ,
    );
  }
}

I have a collection called status in Firebase. I'm trying to pull data from here. However I am getting this error.

I tried some solutions but I still get the same errors.
For example; I used StreamBuilder<QuerySnapshot() instead of StreamBuilder(). However, I got this error.
"The getter 'documents' isn't defined for the type 'QuerySnapshot<Object?>'.". Another example,I used docs instead of the word documents. Again I got the same error. Finally, when I removed the words docs or documents I got an error as follows."The getter 'lenght' isn't defined for the type 'QuerySnapshot<Object?>'."

My code:

class Home extends StatefulWidget {
  const Home({Key? key}) : super(key: key);
  @override
  State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
      final FirebaseFirestore _database = FirebaseFirestore.instance;
      final StatusService _statusService = StatusService();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.orange,
        automaticallyImplyLeading: false,
        title: Center(
          child: Text(
            'Home',
            style: TextStyle(color: Colors.white),
          ),
        ),
      ),
      body: StreamBuilder(
        stream: _statusService.getStatus(),
        builder: (BuildContext context, snaphot){
          return !snaphot.hasData
              ? CircularProgressIndicator()
              : ListView.builder(
               itemCount: snaphot.data?.documents.lenght, //Error in here "documents"
              itemBuilder: (context, index){
                DocumentSnapshot mypost = snaphot.data?.documents[index]; // also another error in here " documents"
                return Padding(
                  padding: const EdgeInsets.all(12.0),
                  child: Container(
                    child: Column(children: [
                      Text("${mypost['status']}")
                    ],),
                  ),
                );
          }
          );
        },
      ) ,
    );
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文