Giter Site home page Giter Site logo

tommienu / firestore_collection Goto Github PK

View Code? Open in Web Editor NEW

This project forked from furkansarihan/firestore_collection

0.0 1.0 0.0 588 KB

Firestore extension with cache-first pagination and stream builder support.

License: MIT License

Dart 90.91% Kotlin 0.59% Ruby 6.41% Swift 1.91% Objective-C 0.18%

firestore_collection's Introduction

firestore_collection

This package is used in production but It doesn't provide any warranty. So, be careful with your data!

Firestore extension with cache-first pagination and stream builder support.

firestore_collection - Animated gif demo

Features

  • Cache-first query support.
  • Easy to use with StreamBuilder.
  • Pagination support.
  • Collection listener support. For documents which has greater value related to order field.
  • Remove document-list with BatchWrite.
  • Select documents to remove.
  • Fake remove operation with document update.
  • Custom compare function support for ordering list as desired in ListView.

Usage

Initialize a FirestoreCollection

FirestoreCollection fireCollection = FirestoreCollection(
    collection: FirebaseFirestore.instance
        .collection('posts')
        .doc('post_id')
        .collection("comments"),
    initializeOnStart: true, // first page will be fetched immediately
    offset: 15, // page size
    serverOnly: false, // cache first
    live: true, // notifies to newest docs
    query: FirebaseFirestore.instance
        .collection('posts')
        .doc('post_id')
        .collection("comments"),
    queryOrder: QueryOrder(
        orderField: 'timestamp',
    ),
);

Use it with StreamBuilder

StreamBuilder(
    stream: fireCollection.stream,
    builder: (context, AsyncSnapshot<List<DocumentSnapshot>> snapshot) {
        return ListView.builder(itemBuilder: (context, index) {
            return Text(snapshot.data.elementAt(index).id);
        });
    },
);

Fetch next page

fireCollection.nextPage();

Don't forget to dispose

await fireCollection.dispose();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.