If you want to delete item list using pop up menu in flutter? Add a callback function to your PopUpMenu class:
1 2 3 4 5 6 7 8 9 10 11 12 13 | class PopUpMenu extends StatelessWidget { VoidCallback onDelete; PopUpMenu({this.onDelete}); void showMenuSelection(String value) { switch (value) { case 'Delete': onDelete(); break; // Other cases for other menu options } } |
Then when creating it in your original class:
1 2 3 4 5 6 7 | ... trailing: PopUpMenu( onDelete: () { levelsData.removeWhere((element) => element == element); } ))); } |
General rule of thumb in Flutter is to pass a callback down to children rather than try to access data in a parent.
You may also need to make your StuffInTiles Widget Stateful and add setState(() {}); to your onDelete, as simply removing the value won’t actually update your view with the new list.
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.