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.
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;
case null:
// dialog dismissed
break;
}
}
See also:
- SimpleDialogOption, which are options used in this type of dialog.
- AlertDialog, for dialogs that have a row of buttons below the body.
- Dialog, on which SimpleDialog and AlertDialog are based.
- showDialog, which actually displays the dialog and returns its result.
- material.io/design/components/dialogs.html#simple-dialog
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- SimpleDialog
Constructors
-
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, Color? shadowColor, Color? surfaceTintColor, String? semanticLabel, EdgeInsets? insetPadding, Clip? clipBehavior, ShapeBorder? shape, AlignmentGeometry? alignment}) -
Creates a simple dialog.
const
Properties
- alignment → AlignmentGeometry?
-
The shape of this dialog's border.
final
- backgroundColor → Color?
-
The background color of the surface of this Dialog.
final
-
children
→ List<
Widget> ? -
The (optional) content of the dialog is displayed in a
SingleChildScrollView underneath the title.
final
- clipBehavior → Clip?
-
Controls how the contents of the dialog are clipped (or not) to the given
shape.
final
- contentPadding → EdgeInsetsGeometry
-
Padding around the content.
final
- elevation → double?
-
The z-coordinate of this Dialog.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- insetPadding → EdgeInsets?
-
The amount of padding added to MediaQueryData.viewInsets on the outside
of the dialog. This defines the minimum space between the screen's edges
and the dialog.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- semanticLabel → String?
-
The semantic label of the dialog used by accessibility frameworks to
announce screen transitions when the dialog is opened and closed.
final
- shadowColor → Color?
-
The color used to paint a drop shadow under the dialog's Material,
which reflects the dialog's elevation.
final
- shape → ShapeBorder?
-
The shape of this dialog's border.
final
- surfaceTintColor → Color?
-
The color used as a surface tint overlay on the dialog's background color,
which reflects the dialog's elevation.
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
- titleTextStyle → TextStyle?
-
Style for the text in the title of this SimpleDialog.
final
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.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent 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 DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → 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 ==(
Object other) → bool -
The equality operator.
inherited