SimpleDialog class

A simple material design dialog.

A simple dialog offers the user a choice between several options. A simple dialog has an optional title that is displayed above the choices.

Choices are normally represented using SimpleDialogOption widgets. If other widgets are used, see contentPadding for notes regarding the conventions for obtaining the spacing expected by Material Design.

For dialogs that inform the user about a situation, consider using an AlertDialog.

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

In this example, the user is asked to select between two options. These options are represented as an enum. The showDialog method here returns a Future that completes to a value of that enum. If the user cancels the dialog (e.g. by hitting the back button on Android, or tapping on the mask behind the dialog) then the future completes with the null value.

The return value in this example is used as the index for a switch statement. One advantage of using an enum as the return value and then using that to drive a switch statement is that the analyzer will flag any switch statement that doesn't mention every value in the enum.

Future<void> _askedToLead() async {
  switch (await showDialog<Department>(
    context: context,
    builder: (BuildContext context) {
      return SimpleDialog(
        title: const Text('Select assignment'),
        children: <Widget>[
            onPressed: () { Navigator.pop(context, Department.treasury); },
            child: const Text('Treasury department'),
            onPressed: () { Navigator.pop(context, Department.state); },
            child: const Text('State department'),
  )) {
    case Department.treasury:
      // Let's go.
      // ...
    case Department.state:
      // ...

See also:



SimpleDialog({Key key, Widget title, EdgeInsetsGeometry titlePadding: const EdgeInsets.fromLTRB(24.0, 24.0, 24.0, 0.0), TextStyle titleTextStyle, List<Widget> children, EdgeInsetsGeometry contentPadding: const EdgeInsets.fromLTRB(0.0, 12.0, 0.0, 16.0), Color backgroundColor, double elevation, String semanticLabel, ShapeBorder shape})
Creates a simple dialog. [...]


backgroundColor Color
The background color of the surface of this Dialog. [...]
children List<Widget>
The (optional) content of the dialog is displayed in a SingleChildScrollView underneath the title. [...]
contentPadding EdgeInsetsGeometry
Padding around the content. [...]
elevation double
The z-coordinate of this Dialog. [...]
hashCode int
The hash code for this object. [...]
@nonVirtual, read-only, inherited
key Key
Controls how one widget replaces another widget in the tree. [...]
final, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
semanticLabel String
The semantic label of the dialog used by accessibility frameworks to announce screen transitions when the dialog is opened and closed. [...]
shape ShapeBorder
The shape of this dialog's border. [...]
title Widget
The (optional) title of the dialog is displayed in a large font at the top of the dialog. [...]
titlePadding EdgeInsetsGeometry
Padding around the title. [...]
titleTextStyle TextStyle
Style for the text in the title of this SimpleDialog. [...]


build(BuildContext context) Widget
Describes the part of the user interface represented by this widget. [...]
createElement() StatelessElement
Creates a StatelessElement to manage this widget's location in the tree. [...]
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children. [...]
@protected, inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
toDiagnosticsNode({String name, DiagnosticsTreeStyle style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep. [...]
toString({DiagnosticLevel minLevel:}) String
Returns a string representation of this object.
toStringDeep({String prefixLineOne: '', String prefixOtherLines, DiagnosticLevel minLevel: DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants. [...]
toStringShallow({String joiner: ', ', DiagnosticLevel minLevel: DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object. [...]
toStringShort() String
A short, textual description of this widget.


operator ==(Object other) bool
The equality operator. [...]
@nonVirtual, inherited