Solved: Flutter getx refresh controller when back from another controller

Question

Asked by Mohamed A on December 15, 2021 (source).

I have a screen with a list of items , when I click on an item it opens a page with another controller with item details , item details contains a delete button , when I delete the item and go back to the first screen , the deleted item is still there and I must restart the app to disappear , How to make that approach ?

Answer

Question answered by S. M (source).

You need to remove the deleted item from your ListController's list as well. Your DetailsController's delete method should look like this:

delete(int id) async{
  await itemService.delete(id);
  final ListController listController = Get.find();

  var index = listController.indexWhere((element) => element.id == id);

  listController.removeAt(index);
  listController.update();

 }
FLUTTER FLUTTER-GETX
SHARE: