Jawad
Jawad

Reputation: 986

Flutter query cache of firestore

I want to get the count of cached data of firestore whether i am offline or online in both conditions to differentiate new and old records in flutter android.

Upvotes: 0

Views: 451

Answers (1)

djalmafreestyler
djalmafreestyler

Reputation: 1909

You can do that for example by using 2 FutureBuilders, using the parameter "source" from ".getDocuments(source: )", you can set Source.cache (retrieves data from the cache) or Source.server (retrieves data from the server).

FutureBuilder(
            future: Firestore.instance.collection("yourCollection").getDocuments(source: Source.cache ),
            builder: (context, snapshot) {

              if (!snapshot.hasData || snapshot.data.documents.length == null) {
                return Center(
                  child: CircularProgressIndicator(
                    valueColor: AlwaysStoppedAnimation(Colors.white),
                  ),
                );
              } else {

               print("Count: ${snapshot.data.documents.length}");

                return Container();


              }
            }
          )

Upvotes: 1

Related Questions