How can I refresh a ListView ?
Let say in page A, I have a ListView, and there is a menu icon in the row item.
When I click the menu icon, it will show a bottom sheet dialog which has a delete icon.
When delete icon is clicked, it will pop up a delete confirmation dialog.
Once the 'Yes' button in confirmation dialog is clicked, it will delete the item. Once it received the "Success" status, it will refresh the ListView.
This is the code for bottom sheet delete icon
onTap: () {
Navigator.pop(context);
var result = PopUpDialog().showDeleteDialog(); // pop up confirmation dialog
if (result == 'Success') {
print('success');
setState(() {
data.removeAt(index);
});
} else {
print('fjeodpedp');
}
},
And this is the code for Yes button in confirmation dialog.
PopUpDialog-showDeleteDialog
onPressed: () async {
Navigator.pop(buildContext); // dismiss confirmation dialog
var result = await _bloc.delete();
return result;
},
Bloc class
Future delete() async {
Response delete = await _repo.delete(); // delete data in server
var deleteResponse = Response.fromJson(delete.body);
return deleteResponse.status; // return Success
}
I want the setState get called only if deleteResponse.status is equal to success, but it keep printing fjeodpedp once the confirmation dialog is pop up. I have added async-await, but still not working.
What is the correct way?
Thanks for your valuable time.