i am trying to save data reads which have been not changed yet to avoid more and more the same repeated data that not changed yet ..
i have normal Future.Builder that get data from firstore (network side)
Widget build(BuildContext context) {
return FutureBuilder(
future: FirebaseFirestore.instance.collection('users').get(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) {
return const Expanded(child: SizedBox()) ;
}
return ListView.builder(
itemCount: snapshot.data!.docs.length ,
itemBuilder: (context, int index) {
DocumentSnapshot documentSnapshot = snapshot.data!.docs[index];
return ListView.builder(
itemCount: snapshot.data!.docs.length ,
itemBuilder: (context, int index) {
DocumentSnapshot documentSnapshot = snapshot.data!.docs[index];
return Text(documentSnapshot['products'])
}
);
}
}
and i have into every single document Timestamp
and i need to use where('modify',isGreaterThen : HERE i need to put the old timestamp from cashe to chick if it not changed yet to decide to fetch the new ones
in flutter i cannot handle it as well .. How can i fetch the cashed data with the new ones from network in the harmonic index such as reading the whole data in normal way .. so i avoided these old ones to be reload again ..
i have read a lot of this topic but it was in old Firestore
version also it was using java code ...
this following code that cannot handle in flutter
Source CACHE = Source.CACHE;
Source SERVER = Source.SERVER;
Query.Direction DESCENDING = Query.Direction.DESCENDING;
FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
CollectionReference shoesRef = rootRef.collection("shoes");
Query lastAddedQuery = shoesRef.orderBy("lastModified", DESCENDING)
shoesRef.get(CACHE).addOnCompleteListener(task -> {
if (task.isSuccessful()) {
boolean isEmpty = task.getResult().isEmpty();
if (isEmpty) {
shoesRef.get(SERVER).addOnCompleteListener(/* ... */);
}
}
});
Query query = shoesRef.orderBy("lastModified", DESCENDING)
.whereGreaterThan("lastModified", savedDate);
source code was written by Alex Mamo
any support or example with latest version of Firbase and in dart or flutter code will be so thankful ..
best regards