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

Overview

Firestore Cache

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

pub package docs MIT License GitHub Actions codecov style: flutter_lints

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.2.0

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:firestore_cache/firestore_cache.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

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

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

final Query query = Firestore.instance.collection('collection');
final QuerySnapshot snapshot = await FirestoreCache.getDocuments(
    query: query,
    cacheDocRef: cacheDocRef,
    firestoreCacheField: cacheField,
);
Comments
Releases(v2.3.0)
  • v2.3.0(Oct 20, 2022)

  • v2.2.1(Apr 10, 2022)

  • v2.2.0(Dec 1, 2021)

  • v2.1.1(Jun 5, 2021)

  • v2.1.0(Jun 5, 2021)

    • fix: Fix types mismatch between firestore_cache and cloud_firestore

    • BREAKING: Add Map<String, dynamic> type to DocumentReference, DocumentSnapshot, Query and QuerySnapshot

    • BREAKING: getDocument has been updated with the following function signature:

      Future<DocumentSnapshot<Map<String, dynamic>>> getDocument(
        DocumentReference<Map<String, dynamic>> docRef, {
        Source source = Source.cache,
        bool isRefreshEmptyCache = true,
      });
      
    • BREAKING: getDocuments has been updated with the following function signature:

      Future<QuerySnapshot<Map<String, dynamic>>> getDocuments({
        required Query<Map<String, dynamic>> query,
        required DocumentReference<Map<String, dynamic>> cacheDocRef,
        required String firestoreCacheField,
        String? localCacheKey,
        bool isUpdateCacheDate = true,
      });
      
    Source code(tar.gz)
    Source code(zip)
  • v2.0.0(May 21, 2021)

  • v1.0.0+1(Apr 2, 2021)

  • v1.0.0(Mar 29, 2021)

  • v0.3.0(Mar 29, 2021)

  • v0.2.0+1(Mar 29, 2021)

    • chore: Bump cloud_firestore: ">=0.14.0 <0.15.0"
    • chore: Bump meta: ">=1.0.0 <1.3.1"
    • chore: Bump shared_preferences: ">=0.5.0 <2.0.0"
    • chore: Remove firebase_core
    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Mar 29, 2021)

  • v0.1.1(Mar 29, 2021)

  • v0.1.0(Mar 29, 2021)

⚡ Cache Manager A tidy utility to handle cache of your flutter app like a Boss.

⚡ Cache Manager A tidy utility to handle cache of your flutter app like a Boss. It provides support for both iOS and Android platforms (offcourse). ??

Abhishek Chavhan 10 Oct 25, 2022
A most easily usable cache management library in Dart. With CacheStorage, you can easily manage cache on your application.

A most easily usable cache management library in Dart! 1. About 1.1. Introduction 1.1.1. Install Library 1.1.2. Import It 1.1.3. Use CacheStorage 1.2.

Kato Shinya 1 Dec 13, 2021
Memory Cache is simple, fast and global in-memory cache with CRUD features.

Memory Cache Memory Cache is simple, fast and global in-memory cache. Features Create, read, update, delete and invalidate cache. Expirable Cache Gett

Gökberk Bardakçı 6 Dec 25, 2022
Implementing simple storage operations, CRUD (Create, Read, Update, Delete), using Firebase Firestore

CRUD Firebase Implementing simple storage operations, CRUD (Create, Read, Update

Luciano Martins 6 Oct 29, 2022
Automatically generate profile picture with random first name and background color. But you can still provide pictures if you have them. As the default color, based on the name of the first letter. :fire: :fire: :fire:

FLUTTER PROFILE PICTURE Automatically generate profile picture with random first name and background color. But you can still provide pictures if you

Aditya Dharmawan Saputra 10 Dec 20, 2022
Flutter plugin for auto resize widgets to get then "responsives".

Responsive Widgets This plugin helps to create responsive widgets, that makes auto-size with the proportion between reference screen size (width, heig

Lucas Henrique Polazzo 45 Nov 3, 2022
Learn how to build a tensorflow model on Techable Machine and then run it on flutter app.

Ml With Flutter Learn how to build a tensorflow model on Techable Machine and then run it on flutter app. Youtube Tutorial Show Support Recommend Me O

Sanskar Tiwari 133 Jan 3, 2023
From then on, developers only need to master one Button component, which is enough.

FButton From then on, developers only need to master one Button component, which is enough. Support corners, borders, icons, special effects, loading

Fliggy Mobile 198 Nov 22, 2022
This is a MVP our app's. The app get the song's list on firebase and display then you can be listen App features.

music_app Requirements: flutter version 3.0.3 Dart 2.17.5 Firebase CLI 11.1.0 flutter sdk: >= 2.15.1 < 3.0.0 flutter dependentcies: http: 0.13.4 mvvm:

Lê Hồng Minh 3 Aug 2, 2022
A Flutter plugin to read 🔖 metadata of 🎵 media files. Supports Windows, Linux & Android.

flutter_media_metadata A Flutter plugin to read metadata of media files. A part of Harmonoid open source project ?? Install Add in your pubspec.yaml.

Harmonoid 60 Dec 2, 2022
This repository is Online_Learning Screen UI - Flutter. I am fetching the data from the local JSON API.

online_learning A new Flutter Online_Learning application. Designed by Arun PP, Code with Flutter by Kishor Kc. Kishor Kc I am fetching the data from

Kishor Kc 14 Jul 5, 2022
A Flutter application with proper navigation and routes handling and API data fetching and posting.

Flutter-Navigation-and-API-Integration A Flutter application with proper navigation and routes handling and API data fetching and posting. ⏮ Preview G

Ehmad Saeed⚡ 7 Oct 5, 2022
A fully functional Movies Application built with Flutter. The application built with null safety and clean architecture, also uses OMDB API for fetching movies in the search item

Cinema DB Project Details This project uses null safety feature Project uses clean code architecture (Uncle Bob's Architecture) Project can run on bot

Dhruvam 2 Oct 1, 2022
A google browser clone which is made by using flutter and fetching the google search api for the search requests.

google_clone A new Flutter project. Project Preview Getting Started This project is a starting point for a Flutter application. A few resources to get

Priyam Soni 2 May 31, 2022
This is an applications for fetching pokemon data from API and showed in Listview with infinity scrolling

pokedex This is an applications for fetching pokemon data from API and showed in Listview with infinity scrolling #Author Created by Yusril Rapsanjani

Yusril Rapsanjani 9 Dec 13, 2019
Fetching API with dart language.

TODO: Put a short description of the package here that helps potential users know whether this package might be useful for them. Features TODO: List w

Hemant Gauhai 1 Dec 21, 2021
A font loader to download, cache and load web fonts in flutter with support for Firebase Cloud Storage.

Dynamic Cached Fonts A simple, easy to use yet customizable font loader to use web fonts. Demo: https://sidrao2006.github.io/dynamic_cached_fonts ?? I

Aneesh Rao 18 Dec 21, 2022
🧾 Flutter widget allowing easy cache-based data display in a ListView featuring pull-to-refresh and error banners.

Often, apps just display data fetched from some server. This package introduces the concept of fetchable streams. They are just like normal Streams, b

Marcel Garus 17 Jan 18, 2022