firebase_pagination 4.2.0

SDKflutter
Platformandroidiosmacosweb

A flutter package to paginate realtime database and firestore with live updates.

Firebase Pagination

A simple and effective way to Paginate Firebase related data.

pub package GitHub

GitHub issues open GitHub issues closed


Realtime DatabaseFirestore
RealtimeDB Ascending Pagination DemoFirestore 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

PropertyDescriptionTypeDefault
queryThe query to use to fetch data from Firestore / Realtime Database.Query-
itemBuilderThe builder to use to build the items in the list.Function-
separatorBuilderThe builder to use to render the separator.FunctionseparatorBuilder (package fn)
limitThe number of items to fetch from Database at once.int10
viewTypeThe type of view to use for the list.ViewTypeViewType.list
isLiveWhether to fetch newly added items as they are added to Database.boolfalse
gridDelegateThe delegate to use for the GridView.SliverGridDelegatecrossAxisCount: 2
wrapOptionsThe Wrap widget properties to use.WrapOptionsWrapOptions()
pageOptionsThe PageView widget properties to use.PageOptionsPageOptions()
onEmptyThe widget to use when data is empty.WidgetEmptyScreen()
bottomLoaderThe widget to use when more data is loading.WidgetBottomLoader()
initialLoaderThe widget to use when data is loading initially.WidgetInitialLoader()
scrollDirectionThe scrolling direction of the ScrollView.Axisfalse
reverseWhether the ScrollView scrolls in the reading direction.boolfalse
shrinkWrapShould the ScrollView be shrink-wrapped.boolfalse
physicsThe scroll behavior to use for the ScrollView.ScrollPhysics-
paddingThe padding to use for the ScrollView.EdgeInsetsGeometry-
controllerThe controller to use for the ScrollView.ScrollControllerScrollController()
pageControllerThe controller to use for the PageView.PageControllerPageController()
descendingWhether the data should be fetched in descending order or not. Only works for RealtimeDBPaginationboolfalse

If you liked the package, then please give it a Like 👍🏼 and Star ⭐