How to dismiss an AlertDialog on a FlatButton click?
Navigator.pop() should do the trick. You can also use that to return the result of the dialog (if it presented the user with choices)
Navigator.pop() should do the trick. You can also use that to return the result of the dialog (if it presented the user with choices)
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
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