This is a repost of an answer I wrote on Stack Overflow.
If you need to display a message to a user and give them time to read it or request a response from them, you can use an AlertDialog
. This is the equivalent of an Android AlertDialog
or an iOS UIAlertController
. The examples below show a basic setup for one, two, and three buttons.
One Button
showAlertDialog(BuildContext context) { // set up the button
Widget okButton = FlatButton(
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 alert;
},
);
}
Two Buttons
showAlertDialog(BuildContext context) { // set up the buttons
Widget cancelButton = FlatButton(
child: Text("Cancel"),
onPressed: () {},
);
Widget continueButton = FlatButton(
child…