Home > Software design >  Is there any method that I can open an alert dialog with list of choices in flutter based on an if c
Is there any method that I can open an alert dialog with list of choices in flutter based on an if c

Time:06-23

So basically I have a countdown timer for a minute and when the minute finishes I want an alert dialog to pop on the screen for the user e.g:

if (isCompleted) {
      //open the dialog widget here
}

I can't find solutions for that. I'm only finding solutions that opens the dialog on button press. Can anyone help?

CodePudding user response:

I used this in a project of mine to display an info dialog when opening the app for the first time:

Future.delayed(Duration(milliseconds: 500), () {
                            showDialog(
                              context: context,
                              builder: (context) => AlertDialog(
                                       //etc
                                )

You can probably wrap your widgets in a FutureBuilder (so you have access to context) with your countdown as the future argument, and, when the countdown is over, you can call showDialog from there.

  • Related