【问题标题】:Error: The getter 'docs' isn't defined for the class 'Object'. - 'Object' is from 'dart:core'错误:没有为类“对象”定义吸气剂“文档”。 - “对象”来自“飞镖:核心”
【发布时间】:2021-07-15 08:34:45
【问题描述】:

我在从 Firebase Cloud Firestore 获取消息时遇到问题。显示的错误是:'Error: The getter 'docs' isn't defined for the class 'Object' - 'Object' is from 'dart:core'.'

下面是我的代码:

class ChatScreen extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
        return Scaffold(
          body: StreamBuilder<Object>(
              stream: FirebaseFirestore.instance
                  .collection('chats/EKLJIb8ZfRoDTqxkkJaB/messages')
                  .snapshots(),
              builder: (context, chatSnapshot) {
                return ListView.builder(
                  itemCount: chatSnapshot.data.**docs**.length,
                  itemBuilder: (ctx, index) => Container(
                    padding: EdgeInsets.all(8),
                    child: Text('this work'),
                  ),
                );
              }),
          floatingActionButton: FloatingActionButton(
            child: Icon(Icons.add),
            onPressed: null,
          ),
      );
   }
}

【问题讨论】:

    标签: firebase flutter google-cloud-firestore


    【解决方案1】:

    改变这个:

    body: StreamBuilder<Object>(
    

    进入这个:

    body: StreamBuilder<QuerySnapshot>(
    

    docsQuerySnapshot 类下的属性,而不是 Object 类下的属性

    【讨论】:

      【解决方案2】:

      我已经通过在 StreamBuilder 之后将数据类型添加为动态来解决它,在我的情况下,答案“Peter Haddad”对我不起作用,我遇到了完全相同的错误。

      我就是这样解决的:

      StreamBuilder<dynamic>(....Your Code here....)
      

      【讨论】:

        猜你喜欢
        • 2021-08-22
        • 1970-01-01
        • 2021-09-29
        • 2021-08-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-22
        • 1970-01-01
        相关资源
        最近更新 更多