How to check if a widget is removed or not?

515 Views Asked by At

I want to display some Alert Dialogs in succession, i.e. when the user closes the first one, the second one gets displayed, and so on.

But I get an error if the previous Alert Dialog is not popped (removed from the display) and the program tries to display the next one.

How can I check if a widget (in this case, AlertDialog) exists on the screen?

1

There are 1 best solutions below

0
On

You must be using something like showDialog to show it, so after the end of showDialog parenthesis add whenComplete method and add the code that you want to execute after the dialog is popped up.

showDialog(....
....
...).whenComplete(() => setState(() => _isDialogOpen = false));