搜索插件、代码仓与 APP 分类

插件详情v4.3.0

firebase_pagination

一个用于实时数据库和 Firestore 分页并支持实时更新的 Flutter 包。

AndroidiOSWebmacOSWindows
近 30 天下载
2930
喜欢数
92
Pub 分数
160

安装插件

flutter pub add firebase_pagination

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Firebase Pagination 是一个 Flutter 包,旨在高效地从 Firebase 实时数据库和 Firestore 分页数据,并支持实时更新。它简化了逐步加载大型数据集的过程,确保流畅的性能和实时同步。该包可无缝集成到 Flutter 的 ListView 及其他可滚动小部件中,自动处理分页逻辑,例如加载状态和列表末尾检测。非常适合需要动态、响应式数据流的应用程序,如聊天界面、社交媒体动态或内容列表。

适合场景

  • 实时聊天应用
  • 社交媒体动态实现
  • 内容密集型仪表板
  • 动态列表加载与实时更新
  • 离线可用的数据获取

主要特点

  • 来自 Firebase 的实时更新
  • 自动分页处理
  • 支持实时数据库和 Firestore
  • 内置的加载和错误状态
  • 与 ListView 和 ScrollViews 的无缝集成

适合对象

  • 使用 Firebase 构建实时应用的开发者
  • 需要高效数据加载的应用程序
  • 需要离线支持和同步的项目
  • 使用 Flutter 和 Firebase 后端的团队

使用建议

  • 需要 Firebase 设置和配置
  • 可能需要为大型数据集定制缓存策略
  • 仅限 Firebase 源
  • 性能取决于网络状况和数据大小

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Firebase Pagination

A simple and effective way to Paginate Firebase related data.

pub package GitHub

GitHub issues open GitHub issues closed


Realtime Database Firestore
RealtimeDB Ascending Pagination Demo Firestore Pagination Demo
RealtimeDB Descending Pagination Demo

Features

  • FirestorePagination to simplify paginating firestore collections.
  • RealtimeDBPagination to simplify paginating realtime database nodes.
  • Get live updates when new data is added using isLive property.
  • Get realtime changes on already loaded data.
  • Descending pagination for RealtimeDBPagination.

Getting started

Add to Dependencies
firebase_pagination: ^4.2.0
Import the package
import 'package:firebase_pagination/firebase_pagination.dart';

Usage

Simplest Firestore Pagination
FirestorePagination(
  query: FirebaseFirestore.instance.collection('scores').orderBy('score'),
  itemBuilder: (context, docs, index) {
    final data = docs[index].data() as Map<String, dynamic>;

    // Do something cool with the data
  },
),
Simplest Firebase Realtime Database Pagination
RealtimeDBPagination(
  query: FirebaseDatabase.instance.ref().child('scores').orderByChild('score'),
  orderBy: 'score',
  itemBuilder: (context, dataNodes, index) {
    final data = dataNodes[index].value as Map<String, dynamic>;

    // Do something cool with the data
  },
),
For more examples, see the examples section.

How it Works

  • A data listener is added to the query with the given limit.
  • Every time the user scrolls to the bottom of the list, the limit is increased.
  • If there are any changes for the loaded data, it will be automatically updated.
  • If isLive is true, a live listener is added to fetch data before the first load. (i.e. Newly added data will be automatically loaded)
  • When new data is added, the data listener will be removed and a new data listener will be added with the new limit.
  • Also the live listener will be removed and a new live listener will be added.

Efficiency & Performance

  • Both FirestorePagination and RealtimeDBPagination uses maximum of two stream listeners to fetch data.
  • Hence it is performant and uses minimum amount of resources.
  • The listeners are automatically removed when the widget is removed from the widget tree.
  • For fetching data, the widgets uses this hack to minimize the number of reads from the database.

Description

Property Description Type Default
query The query to use to fetch data from Firestore / Realtime Database. Query -
itemBuilder The builder to use to build the items in the list. Function -
separatorBuilder The builder to use to render the separator. Function separatorBuilder (package fn)
limit The number of items to fetch from Database at once. int 10
viewType The type of view to use for the list. ViewType ViewType.list
isLive Whether to fetch newly added items as they are added to Database. bool false
gridDelegate The delegate to use for the GridView. SliverGridDelegate crossAxisCount: 2
wrapOptions The Wrap widget properties to use. WrapOptions WrapOptions()
pageOptions The PageView widget properties to use. PageOptions PageOptions()
onEmpty The widget to use when data is empty. Widget EmptyScreen()
bottomLoader The widget to use when more data is loading. Widget BottomLoader()
initialLoader The widget to use when data is loading initially. Widget InitialLoader()
scrollDirection The scrolling direction of the ScrollView. Axis false
reverse Whether the ScrollView scrolls in the reading direction. bool false
shrinkWrap Should the ScrollView be shrink-wrapped. bool false
physics The scroll behavior to use for the ScrollView. ScrollPhysics -
padding The padding to use for the ScrollView. EdgeInsetsGeometry -
controller The controller to use for the ScrollView. ScrollController ScrollController()
pageController The controller to use for the PageView. PageController PageController()
descending Whether the data should be fetched in descending order or not. Only works for RealtimeDBPagination bool false
If you liked the package, then please give it a Like 👍🏼 and Star ⭐

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目

暂无相关数据。