Skip to content

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

License

Notifications You must be signed in to change notification settings

tommienu/firestore_collection

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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();

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 90.9%
  • Ruby 6.4%
  • Swift 1.9%
  • Other 0.8%