Is there a way to update the state when I use both Getbuilder() + FutureBuilder()
I have list of users in firebase document, I display these users using Futurebuilder
I want when i click on any user, that user get deleted I managed to delete the user successfully from firebase but in the UI the user is still shown, so i need to go back and refresh the page.
Here is an example
GetBuilder<BlockedAccountController>(
builder: (controller) {
return FutureBuilder(
future: controller.userDoc,
builder: ((context, snapshot) {
if (snapshot.hasData) {
return ListView.builder(
itemCount: snapshot.data!["blockusers"].length,
shrinkWrap: true,
itemBuilder: (context, index) {
return Container(
color: mainappColor,
height: 50,
width: double.infinity,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Text(
snapshot.data!["blockusers"][index],
style: TextStyle(fontSize: 20),
),
),
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: InkWell(
onTap: () async {
await unblockAccount(currentusername,
snapshot.data!["blockusers"][index]);
controller.refresh();
},
child: Container(
decoration: BoxDecoration(
color: Colors.purple,
borderRadius: BorderRadius.all(
Radius.circular(5))),
alignment: Alignment.center,
width: 80,
height: 40,
child: Text("unblock".tr),
),
),
)
],
),
);
},
);
} else {
return Text("");
}
}));
},
)
And the controller
class BlockedAccountController extends GetxController {
late Future<DocumentSnapshot<Map<String, dynamic>>> userDoc;
void refresh() {
update();
}
@override
void onInit() {
userDoc = FirebaseFirestore.instance
.collection("users")
.doc(currentusername)
.get();
super.onInit();
}
}
When I click the button to unBlock the user the UI does not refresh, why?
Thank you.