I am using GetX and FutureBuilder to build a list of Cards from my DB. Lets say I have 10 products in DB then 10 cards are shown. When I add one more product, the Cards on the HomeScreen aren't updated and I have to Navigate in and Out of page to show the 11th product.
How can I force the update i.e. probably make a "Refresh" button that may load the latest data.
PS: I do not want to use STREAM-BUILDER as I don't wish to listen to all changes actively but only when needed. I also cannot use SetState() as I am using GetX hence no StatefulWidget.
Here is my Card class:
FutureBuilder(
future: databaseController.getData()
builder: (context, snapshot) {
return StaggeredGridView.countBuilder(
itemCount: snapshot.data.length,
crossAxisCount: 2,
itemBuilder: (BuildContext context, int index) =>
GetX<FindDeviceLocation>(builder: (controller) {
return CreateTheCard(
lindex: index,
location: snapshot.data[index]["location"],
summary: snapshot.data[index]["summary"],
description: snapshot.data[index]["description"],
category: snapshot.data[index]["category"],
imageURL: snapshot.data[index]["adImage"],
onTapFunction: () => Get.to(DetailPage(
post: snapshot.data[index],
)));
}),
This is my method that fetches data from DB:
Future getData() async {
QuerySnapshot _firebaseDb = await FirebaseFirestore.instance
.collection("items")
.where("status", isEqualTo: true)
.orderBy("postTime", descending: true)
.get();
return _firebaseDb.docs;
}
var gettingDataCompleted = false.obs
and inside builder check it for rebuild.