How to make an AlertDialog in Flutter?

One Button showAlertDialog(BuildContext context) { // set up the button Widget okButton = TextButton( child: Text(“OK”), onPressed: () { }, ); // set up the AlertDialog AlertDialog alert = AlertDialog( title: Text(“My title”), content: Text(“This is my message.”), actions: [ okButton, ], ); // show the dialog showDialog( context: context, builder: (BuildContext context) { return … Read more

How to refresh an AlertDialog in Flutter?

Use StatefulBuilder to use setState inside Dialog and update Widgets only inside of it. showDialog( context: context, builder: (context) { String contentText = “Content of Dialog”; return StatefulBuilder( builder: (context, setState) { return AlertDialog( title: Text(“Title of Dialog”), content: Text(contentText), actions: <Widget>[ TextButton( onPressed: () => Navigator.pop(context), child: Text(“Cancel”), ), TextButton( onPressed: () { setState(() … Read more