How to use AlertDialog and Dismiss Alert
Does you application needs to alert your user or maybe to get input from them? Try using Flutter AlertDialog widget and dismiss alert dialog with an example.

Does you application needs to alert your user or maybe to get input from them?
Try using Flutter AlertDialog widget.
Here is an example how to use Flutter AlertDialog widget in your project
Future<void> logOut() async {
return showDialog<void>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
title: Text('Are you sure?'),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text('We will be redirected to login page.'),
],
),
),
actions: <Widget>[
FlatButton(
child: Text('No'),
onPressed: () {
Navigator.of(context).pop(); // Dismiss the Dialog
},
),
FlatButton(
child: Text('Yes'),
onPressed: () {
Navigator.of(context).pop(); // Navigate to login
},
),
],
);
},
);
}
Usually content is a Text widget but you can also use Image, SingleChildScrollView, etc.
How to dismiss Alert dialog in Flutter
You can dismiss alert dialog by Navigator.pop(context);
or you can also use
Navigator.pop(context, result);
FlatButton(
child: Text('No'),
onPressed: () {
Navigator.of(context).pop(); // Dismiss alert dialog in flutter
},
)
See also:
- SimpleDialog, which handles the scrolling of the contents but has no actions.
- Dialog, on which AlertDialog and SimpleDialog are based.
- CupertinoAlertDialog, an iOS-styled alert dialog.
- showDialog, which actually displays the dialog and returns its result.
- material.io/design/components/dialogs.html#alert-dialog