Let's say we have ListView.bulider which gets data from Firstore.
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'])
}
);
}
}
Ok. I just read this data which is products .. and then I open the same page again where Future.Bulder is located into stfl class, Will this count as a new read? Even if the data has not changed
in other words, Since stfl class will fetch the data again, will a new reading be calculated every time the user opens the same page many times?
and the same with StreamBuilder?
Should I avoid this with software intervention So that I fetch the data once somehow, such as get data for once at beginning of the app lunch instead of getting them into the general class which users browsing it many times?
CodePudding user response:
then I open the same page again where Future.Bulder is located into stfl class, Will this count as a new read? Even if the data has not changed.
Yes, it will be counted as a new read. I have written an article regarding this topic that will help you for sure understand the billing mechanism:
In other words, since stfl class will fetch the data again, will a new reading be calculated every time the user opens the same page many times?
Yes, and this is because Firestore SDK needs to check the online version of the documents against the cached one each time you perform a new request.
So that I fetch the data once somehow, such as get data for once in the beginning of app lunch instead of getting them into the general class which users browsing it many times?
Yes, you can get it only once, and then pass it into other parts of the application where is needed. I also recommend you also see some techniques used the reduce Firestore costs:
Or:
Or even:
