0

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.

1 Answer 1

1

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


              }
            }
          )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.