I am creating an app to show the latest fuel price for the users, and I'm using a snapshot listener on my Firebase Firestore
database, and per my understanding it should create 1 read per user only when I update the database... I have it installed on 1 device, and get 33 reads for that one device!
The code that connects to Firebase is:
StreamBuilder<DocumentSnapshot>(
stream: FirebaseFirestore.instance
.collection('global')
.doc('inland')
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Text("Loading...",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w700,
fontSize: 34.0));
}
if (snapshot.hasError) {
return Text("Error",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w700,
fontSize: 34.0));
}
if (snapshot.connectionState ==
ConnectionState.waiting) {
return Text("Loading...",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w700,
fontSize: 34.0));
} else {
Map<String, dynamic> document =
snapshot.data.data();
return Text("R " + document['95'],
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w700,
fontSize: 34.0));
}
It is in an AnimatedContainer, but as I understand it, the app shows the price from cache when it doesn't change on the database, so this shouldn't make a difference.
Am I understanding something wrong? And is there a way to fix this?