AlertDialog class

A material design alert dialog.

An alert dialog informs the user about situations that require acknowledgement. An alert dialog has an optional title and an optional list of actions. The title is displayed above the content and the actions are displayed below the content.

If the content is too large to fit on the screen vertically, the dialog will display the title and the actions and let the content overflow, which is rarely desired. Consider using a scrolling widget for content, such as SingleChildScrollView, to avoid overflow. (However, be aware that since AlertDialog tries to size itself using the intrinsic dimensions of its children, widgets such as ListView, GridView, and CustomScrollView, which use lazy viewports, will not work. If this is a problem, consider using Dialog directly.)

For dialogs that offer the user a choice between several options, consider using a SimpleDialog.

Typically passed as the child widget to showDialog, which displays the dialog.

Sample

This snippet shows a method in a State which, when called, displays a dialog box and returns a Future that completes when the dialog is dismissed. assignment Future<void> _showMyDialog() async { return showDialog<void>( context: context, barrierDismissible: false, // user must tap button! builder: (BuildContext context) { return AlertDialog( title: Text('AlertDialog Title'), content: SingleChildScrollView( child: ListBody( children: <Widget>[ Text('This is a demo alert dialog.'), Text('Would you like to approve of this message?'), ], ), ), actions: <Widget>[ FlatButton( child: Text('Approve'), onPressed: () { Navigator.of(context).pop(); }, ), ], ); }, ); }

See also: