Search packages, repositories and app categories

Package detailsv2.21.7

firestore_cache

A Flutter plugin for fetching Firestore documents with read from cache first then server

AndroidiOSWebmacOSWindows
30-day downloads
3.3K
Likes
107
Pub points
160

Install package

flutter pub add firestore_cache

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

firestore_cache is a Flutter package that enables fetching Firestore documents with a read-from-cache-first strategy, ensuring fast local responses while optionally syncing with the server. It prioritizes cached data for immediate display and updates the cache asynchronously from the server, improving app performance and user experience during network delays or offline scenarios. The package supports all major platforms including Android, iOS, Web, macOS, and Windows, making it ideal for applications requiring responsive data access with fallback reliability.

Use cases

  • Offline-first data retrieval
  • Fast initial UI rendering
  • Background sync with Firestore
  • Improved app responsiveness
  • Seamless network recovery

Key features

  • Cache-first document fetching
  • Automatic server sync
  • Cross-platform support
  • Simple API integration
  • Real-time data consistency

Suitable for

  • Apps needing fast local data access
  • Developers implementing offline capabilities
  • Projects using Firebase Firestore
  • UIs requiring instant feedback
  • Applications with unreliable network connections

Considerations

  • May serve stale data initially
  • Requires careful handling of cache invalidation
  • Not suitable for real-time critical updates
  • Limited to Firestore document reads
  • Network usage depends on sync frequency

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

Firestore Cache

pub package docs MIT License GitHub Actions codecov Codacy Badge style: flutter_lints

Github-sponsors BuyMeACoffee Ko-Fi LiberaPay Patreon PayPal

A Flutter plugin for fetching Firestore documents with read from cache first then server.

This plugin is mainly designed for applications using the DocumentReference.get() and Query.get() methods in the cloud_firestore plugin, and is implemented with read from cache first then server.

Getting Started

Add this to your package's pubspec.yaml file:

dependencies:
  firestore_cache: ^2.21.2
Usage

Before using the plugin, you will need to create a document on Firestore and create a timestamp field in that document. See the screenshot below for an example:

Firestore Screenshot

⚠️ PLEASE NOTE This plugin does not compare the documents in the cache and the ones in the server to determine if it should fetch data from the server. Instead, it relies on the timestamp field in the document to make that decision. And so your application should implement the logic to update this field if you want to read new data from the server instead of reading it from the cache.

You should also create different timestamp fields for different collections or documents that you are fetching.

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firestore_cache/firestore_cache.dart';

// This should be the path of the document containing the timestamp field
// that you created
final cacheDocRef = Firestore.instance.doc('status/status');

// This should be the timestamp field in that document
final cacheField = 'updatedAt';

final query = Firestore.instance.collection('posts');
final snapshot = await FirestoreCache.getDocuments(
    query: query,
    cacheDocRef: cacheDocRef,
    firestoreCacheField: cacheField,
);

Categories

Dependencies

Dependency list 2 items

Source repository

Projects using this package

No data available yet.