【问题标题】:type 'List<DocumentSnapShot>' is not a subtype of type 'int'类型“List<DocumentSnapShot>”不是类型“int”的子类型
【发布时间】:2019-07-25 19:14:43
【问题描述】:

我想在从 Firestore 获取数据时显示列表。

StreamBuilder(
      stream: Firestore.instance
          .collection("messages")
          .document(groupChatId)
          .collection(groupChatId)
          .orderBy('timestamp', descending: true)
          .limit(20)
          .snapshots(),
      builder: (context, snapshot) {
          if (!snapshot.hasData) {
            return Center(child: CircularProgressIndicator(valueColor: AlwaysStoppedAnimation<Color>(Colors.red)));
        } else {
          return ListView.builder(
            itemCount: snapshot.data.documents,
            itemBuilder: (context, index) =>
                buildItem(index, snapshot.data.documents[index]),
            reverse: true,
            controller: listScrollController,

          );

我可以成功地将数据发布到 Firestore 中,但不知道为什么我无法检索它

【问题讨论】:

    标签: flutter google-cloud-firestore


    【解决方案1】:

    问题在于这一行

    itemCount: snapshot.data.documents,
    

    试试

    itemCount: snapshot.data.length
    

    itemCount 顾名思义,列表中出现的项目数,参数需要一个 int 而不是一个对象

    【讨论】:

    • itemCount: snapshot.data.length 这并没有解决我的问题我只是犯了一个错误应该是 snapshot.data.documents.length.Anyway 谢谢!
    猜你喜欢
    • 2021-07-15
    • 1970-01-01
    • 2021-08-06
    • 2021-05-10
    • 2020-03-26
    • 2021-03-16
    • 1970-01-01
    • 2020-07-26
    • 1970-01-01
    相关资源
    最近更新 更多