简体   繁体   English

Firebase:如何一次只获取 n 条记录而不是整条记录 firebase 实时数据库?

[英]Firebase: How to get only n records at a time instead of whole record firebase real time database?

I am developing a Flutter application where I need to get 10 records at a time from Firebase Realtime Database.我正在开发一个 Flutter 应用程序,我需要从 Firebase 实时数据库一次获取 10 条记录。 Then on pressing a button, get the next 10 records.然后按下按钮,获取接下来的 10 条记录。 Currently, the code I am using is returning all the records目前,我正在使用的代码正在返回所有记录

final snapshot = (await ref.child('user').get());

Is there a way to get the first 10 records and after button press get the next 10 records?有没有办法获取前 10 条记录,按下按钮后获取下 10 条记录?

Then on pressing a button, get the next 10 records.然后按下按钮,获取接下来的 10 条记录。

What you are looking for is called pagination.您正在寻找的内容称为分页。 The key to solving this problem is to limit the results that are coming from the Realtime Database, and load the next n, on request.解决这个问题的关键是限制来自实时数据库的结果,并根据请求加载下一个 n。 Here is a concrete example:这是一个具体的例子:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM