So I have a list of orders, which I am pulling from FireStore and showing on a page. Only the status part of the order is where I have used StreamBuilder to fetch the real time status. So the StreamBuilder is on a document:
FirebaseFirestore firestore = FirebaseFirestore.instance;
DocumentReference<Map<String, dynamic>> item = firestore
.collection("counterOrders")
.doc(this.widget.orderItem.counterCode)
.collection("liveOrders")
.doc(this.widget.orderItem.liveOrderId);
return StreamBuilder<DocumentSnapshot<Map<String, dynamic>>>(
stream: item.snapshots(),
builder: (context, snapshot) {
Widget widget = Center(child: CircularProgressIndicator());
if (!snapshot.hasData &&
snapshot.connectionState == ConnectionState.active) {
widget = Center(child: Icon(Icons.error));
} else if (snapshot.connectionState == ConnectionState.active &&
snapshot.hasData) {
widget = _getBody(snapshot, context);
} else if (!snapshot.hasData &&
snapshot.connectionState == ConnectionState.waiting) {
widget = Center(
child: SizedBox(
height: 10, width: 10, child: CircularProgressIndicator()),
);
}
return widget;
});
_getBody() is where I am showing the status as text. So on my page there are multiple orders along with its live status. If there is change in the status of one order, I am noticing that all the orders' status is being refreshed, while actually only the order whose status is being changed should be refreshed. Additionally, this whole code is in a StatefulWidget with const constructor. This particular widget is part of my order widget, which shows the status of that order.