I have a code that takes data from firebase. The problem is that i am caching the data once i am getting it and than checking if i cached it the next time i want to take it so i can reduce loading time.
The problem is that when i am changing something in the database, when i refresh the app i still see the old data because i think that it is getting it from the cache.
How can i make it so that when i reset the app, i clear the cache and get the new data?
here is a piece of code that checks if the data is cached or not.
List lists = [];
print(id);
await firestoreInstance
.collection("menu/" + id + "/" + id)
.get(GetOptions(source: Source.cache))
.then((querySnapshot) {
querySnapshot.docs.forEach((result) async {
lists.add(result.data()['name']
);
});
});
if (lists.isEmpty) {
print('aici');
await firestoreInstance
.collection("menu/" + id + "/" + id)
.get()
.then((querySnapshot) {
querySnapshot.docs.forEach((result) async {
lists.add(result.data()['name']);
});
});
return lists;
} else {
return lists;
}
}