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>[
          SimpleDialogOption(
            onPressed: () { Navigator.pop(context, Department.treasury); },
            child: const Text('Treasury department'),
          ),
          SimpleDialogOption(
            onPressed: () { Navigator.pop(context, Department.state); },
            child: const Text('State department'),
          ),
        ],
      );
    }
  )) {
    case Department.treasury:
      // Let's go.
      // ...
    break;
    case Department.state:
      // ...
    break;
  }
}

See also:

Inheritance

Constructors

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

Properties

children List<Widget>
The (optional) content of the dialog is displayed in a SingleChildScrollView underneath the title. [...]
final
contentPadding EdgeInsetsGeometry
Padding around the content. [...]
final
semanticLabel String
The semantic label of the dialog used by accessibility frameworks to announce screen transitions when the dialog is opened and closed. [...]
final
shape ShapeBorder
The shape of this dialog's border. [...]
final
title Widget
The (optional) title of the dialog is displayed in a large font at the top of the dialog. [...]
final
titlePadding EdgeInsetsGeometry
Padding around the title. [...]
final
hashCode int
The hash code for this object. [...]
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

Methods

build(BuildContext context) Widget
Describes the part of the user interface represented by this widget. [...]
override
createElement() StatelessElement
Creates a StatelessElement to manage this widget's location in the tree. [...]
inherited
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. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toDiagnosticsNode({String name, DiagnosticsTreeStyle style }) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by toStringDeep. [...]
inherited
toString({DiagnosticLevel minLevel: DiagnosticLevel.debug }) String
Returns a string representation of this object.
inherited
toStringDeep({String prefixLineOne: '', String prefixOtherLines, DiagnosticLevel minLevel: DiagnosticLevel.debug }) String
Returns a string representation of this node and its descendants. [...]
inherited
toStringShallow({String joiner: ', ', DiagnosticLevel minLevel: DiagnosticLevel.debug }) String
Returns a one-line detailed description of the object. [...]
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(dynamic other) bool
The equality operator. [...]
inherited