首页 > 解决方案 > 我们如何限制从 Firebase 获得的快照数量?

问题描述

我正在开发一个 Flutter 消息传递应用程序,我在其中使用 Friebase 作为数据库。每次加载消息时,它都会一次加载所有消息。我希望它一次只加载 x 个数据。我尝试使用限制,但没有帮助。

body: new Column(children: <Widget>[
      new StreamBuilder<QuerySnapshot>(
        stream: Firestore.instance
            .collection('messages')
            .where("threadId", isEqualTo: thread.id)
            .limit(10)
            .snapshots,

标签: firebasefluttergoogle-cloud-firestore

解决方案


我用过.limit(number),效果很好。也许你应该检查你的 where 条件。顺便说一句,你的语法.snapshots不正确,它必须是.snapshots()


推荐阅读