我们如何限制从Firebase获得的快照数量?

时间:2018-08-16 16:52:32

标签: firebase flutter google-cloud-firestore

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

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

2 个答案:

答案 0 :(得分:1)

我使用了.limit(number),它运行完美。 也许您应该检查您的条件。 顺便说一句,您在.snapshots的语法不正确,它必须为.snapshots()

答案 1 :(得分:0)

也许在流上使用take(int count)吗?

参见此处:https://www.dartlang.org/tutorials/language/streams