Skip to main content

AlertDialog

Struct AlertDialog 

Source
pub struct AlertDialog {
Show 28 fields pub key: Option<KeyRef>, pub icon: Option<WidgetRef>, pub icon_color: Option<Color>, pub icon_padding: Option<EdgeInsetsGeometry>, pub title: Option<WidgetRef>, pub title_padding: Option<EdgeInsetsGeometry>, pub title_text_style: Option<TextStyle>, pub content: Option<WidgetRef>, pub content_padding: Option<EdgeInsetsGeometry>, pub content_text_style: Option<TextStyle>, pub actions: Option<Vec<WidgetRef>>, pub actions_padding: Option<EdgeInsetsGeometry>, pub actions_alignment: Option<MainAxisAlignment>, pub actions_overflow_alignment: Option<OverflowBarAlignment>, pub actions_overflow_direction: Option<VerticalDirection>, pub actions_overflow_button_spacing: Option<f64>, pub button_padding: Option<EdgeInsetsGeometry>, pub background_color: Option<Color>, pub elevation: Option<f64>, pub shadow_color: Option<Color>, pub surface_tint_color: Option<Color>, pub semantic_label: Option<String>, pub inset_padding: Option<EdgeInsets>, pub clip_behavior: Option<Clip>, pub shape: Option<ShapeBorderRef>, pub alignment: Option<AlignmentGeometry>, pub constraints: Option<BoxConstraints>, pub scrollable: bool, /* private fields */
}
Expand description

A Material Design alert dialog.

An alert dialog (also known as a basic dialog) informs the user about situations that require acknowledgment. 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.

One set of setters serves both of Dart’s constructors, AlertDialog::new and AlertDialog::adaptive.

See also:

Fields§

§key: Option<KeyRef>§icon: Option<WidgetRef>

An optional icon to display at the top of the dialog.

Typically, an Icon widget. Providing an icon centers the title’s text.

§icon_color: Option<Color>

Color for the Icon in the icon of this AlertDialog.

If null, DialogThemeData::icon_color is used. If that is null, defaults to color scheme’s ColorScheme::secondary if ThemeData::use_material3 is true, black otherwise.

§icon_padding: Option<EdgeInsetsGeometry>

Padding around the icon.

If there is no icon, no padding will be provided. Otherwise, this padding is used.

This property defaults to providing 24 pixels on the top, left, and right of the icon. If title is not null, 16 pixels of bottom padding is added to separate the icon from the title. If the title is null but content is not null, then no bottom padding is added. If both the title and content are null, 24 pixels of padding are added to the bottom.

§title: Option<WidgetRef>

The (optional) title of the dialog is displayed in a large font at the top of the dialog, below the (optional) icon.

Typically a Text widget.

§title_padding: Option<EdgeInsetsGeometry>

Padding around the title.

If there is no title, no padding will be provided. Otherwise, this padding is used.

This property defaults to providing 24 pixels on the top, left, and right of the title. If the content is not null, then no bottom padding is provided (but see content_padding). If it is null, then an extra 20 pixels of bottom padding is added to separate the title from the actions.

§title_text_style: Option<TextStyle>

Style for the text in the title of this AlertDialog.

If null, DialogThemeData::title_text_style is used. If that’s null, defaults to TextTheme::headline_small of ThemeData::text_theme if ThemeData::use_material3 is true, TextTheme::title_large otherwise.

§content: Option<WidgetRef>

The (optional) content of the dialog is displayed in the center of the dialog in a lighter font.

Typically this is a SingleChildScrollView that contains the dialog’s message. As noted in the AlertDialog documentation, it’s important to use a SingleChildScrollView if there’s any risk that the content will not fit, as the contents will otherwise overflow the dialog.

The horizontal dimension of this widget is defined by the IntrinsicWidth widget. As a result, the content cannot use lazy-loading widgets such as ListView, GridView, or CustomScrollView without being given a fixed width.

§content_padding: Option<EdgeInsetsGeometry>

Padding around the content.

If there is no content, no padding will be provided. Otherwise, padding of 20 pixels is provided above the content to separate the content from the title, and padding of 24 pixels is provided on the left, right, and bottom to separate the content from the other edges of the dialog.

If ThemeData::use_material3 is true, the top padding separating the content from the title defaults to 16 pixels instead of 20 pixels.

§content_text_style: Option<TextStyle>

Style for the text in the content of this AlertDialog.

If null, DialogThemeData::content_text_style is used. If that’s null, defaults to TextTheme::body_medium of ThemeData::text_theme if ThemeData::use_material3 is true, TextTheme::title_medium otherwise.

§actions: Option<Vec<WidgetRef>>

The (optional) set of actions that are displayed at the bottom of the dialog with an OverflowBar.

Typically this is a list of TextButton widgets. It is recommended to set the Text::text_align to TextAlign::End for the Text within the TextButton, so that buttons whose labels wrap to an extra line align with the overall OverflowBar’s alignment within the dialog.

If the title is not null but the content is null, then an extra 20 pixels of padding is added above the OverflowBar to separate the title from the actions.

§actions_padding: Option<EdgeInsetsGeometry>

Padding around the set of actions at the bottom of the dialog.

Typically used to provide padding to the button bar between the button bar and the edges of the dialog.

The button_padding may contribute to the padding on the edges of actions as well.

If there are no actions, then no padding will be included.

§actions_alignment: Option<MainAxisAlignment>

Defines the horizontal layout of the actions according to the same rules as for Row::main_axis_alignment.

This parameter is passed along to the dialog’s OverflowBar.

If this parameter is null (the default) then MainAxisAlignment::End is used.

§actions_overflow_alignment: Option<OverflowBarAlignment>

The horizontal alignment of actions within the vertical “overflow” layout.

If the dialog’s actions do not fit into a single row, then they are arranged in a column. This parameter controls the horizontal alignment of widgets in the case of an overflow.

If this parameter is null (the default) then OverflowBarAlignment::End is used.

§actions_overflow_direction: Option<VerticalDirection>

The vertical direction of actions if the children overflow horizontally.

If the dialog’s actions do not fit into a single row, then they are arranged in a column. The first action is at the top of the column if this property is set to VerticalDirection::Down, since it “starts” at the top and “ends” at the bottom. On the other hand, the first action will be at the bottom of the column if this property is set to VerticalDirection::Up, since it “starts” at the bottom and “ends” at the top.

§actions_overflow_button_spacing: Option<f64>

The spacing between actions when the OverflowBar switches to a column layout because the actions don’t fit horizontally.

If the widgets in actions do not fit into a single row, they are arranged into a column. This parameter provides additional vertical space between buttons when it does overflow.

§button_padding: Option<EdgeInsetsGeometry>

The padding that surrounds each button in actions.

This is different from actions_padding, which defines the padding between the entire button bar and the edges of the dialog.

If this property is null, then it will default to 8.0 logical pixels on the left and right.

§background_color: Option<Color>§elevation: Option<f64>§shadow_color: Option<Color>§surface_tint_color: Option<Color>§semantic_label: Option<String>

The semantic label of the dialog used by accessibility frameworks to announce screen transitions when the dialog is opened and closed.

In iOS, if this label is not provided, a semantic label will be inferred from the title if it is not null.

In Android, if this label is not provided, the dialog will use the MaterialLocalizations::alert_dialog_label as its label.

§inset_padding: Option<EdgeInsets>§clip_behavior: Option<Clip>§shape: Option<ShapeBorderRef>§alignment: Option<AlignmentGeometry>§constraints: Option<BoxConstraints>§scrollable: bool

Determines whether the title and content widgets are wrapped in a scrollable.

This configuration is used when the title and content are expected to overflow. Both title and content are wrapped in a scroll view, allowing all overflowed content to be visible while still showing the button bar.

Implementations§

Source§

impl AlertDialog

Source

pub fn new() -> AlertDialog

Creates an alert dialog.

Typically used in conjunction with ShowDialog.

The title_padding and content_padding default to null, which implies a default that depends on the values of the other properties. See the documentation of title_padding and content_padding on how the padding is implemented.

Source

pub fn adaptive() -> AlertDialog

Creates an adaptive AlertDialog based on whether the target platform is iOS or macOS, following Material design’s Cross-platform guidelines.

On iOS and macOS, this constructor creates a CupertinoAlertDialog. On other platforms, this creates a Material design AlertDialog.

Typically passed as a child of ShowAdaptiveDialog, which will display the alert differently based on platform.

If a CupertinoAlertDialog is created only these parameters are used: title, content, actions, scroll_controller, action_scroll_controller, inset_animation_duration, and inset_animation_curve. If a material AlertDialog is created, scroll_controller, action_scroll_controller, inset_animation_duration, and inset_animation_curve are ignored.

The target platform is based on the current Theme: ThemeData::platform.

Source

pub fn key(self, key: KeyRef) -> AlertDialog

Dart AlertDialog(key:).

Source

pub fn icon<K>(self, icon: impl IntoWidget<K>) -> AlertDialog

Dart AlertDialog(icon:).

Source

pub fn icon_padding( self, icon_padding: impl Into<EdgeInsetsGeometry>, ) -> AlertDialog

Dart AlertDialog(iconPadding:).

Source

pub fn icon_color(self, icon_color: Color) -> AlertDialog

Dart AlertDialog(iconColor:).

Source

pub fn title<K>(self, title: impl IntoWidget<K>) -> AlertDialog

Dart AlertDialog(title:).

Source

pub fn title_padding( self, title_padding: impl Into<EdgeInsetsGeometry>, ) -> AlertDialog

Dart AlertDialog(titlePadding:).

Source

pub fn title_text_style(self, title_text_style: TextStyle) -> AlertDialog

Dart AlertDialog(titleTextStyle:).

Source

pub fn content<K>(self, content: impl IntoWidget<K>) -> AlertDialog

Dart AlertDialog(content:).

Source

pub fn content_padding( self, content_padding: impl Into<EdgeInsetsGeometry>, ) -> AlertDialog

Dart AlertDialog(contentPadding:).

Source

pub fn content_text_style(self, content_text_style: TextStyle) -> AlertDialog

Dart AlertDialog(contentTextStyle:).

Source

pub fn actions( self, actions: impl IntoIterator<Item = WidgetRef>, ) -> AlertDialog

Dart AlertDialog(actions:).

Source

pub fn actions_padding( self, actions_padding: impl Into<EdgeInsetsGeometry>, ) -> AlertDialog

Dart AlertDialog(actionsPadding:).

Source

pub fn actions_alignment( self, actions_alignment: MainAxisAlignment, ) -> AlertDialog

Dart AlertDialog(actionsAlignment:).

Source

pub fn actions_overflow_alignment( self, actions_overflow_alignment: OverflowBarAlignment, ) -> AlertDialog

Dart AlertDialog(actionsOverflowAlignment:).

Source

pub fn actions_overflow_direction( self, actions_overflow_direction: VerticalDirection, ) -> AlertDialog

Dart AlertDialog(actionsOverflowDirection:).

Source

pub fn actions_overflow_button_spacing( self, actions_overflow_button_spacing: f64, ) -> AlertDialog

Dart AlertDialog(actionsOverflowButtonSpacing:).

Source

pub fn button_padding( self, button_padding: impl Into<EdgeInsetsGeometry>, ) -> AlertDialog

Dart AlertDialog(buttonPadding:).

Source

pub fn background_color(self, background_color: Color) -> AlertDialog

Dart AlertDialog(backgroundColor:).

Source

pub fn elevation(self, elevation: f64) -> AlertDialog

Dart AlertDialog(elevation:).

Source

pub fn shadow_color(self, shadow_color: Color) -> AlertDialog

Dart AlertDialog(shadowColor:).

Source

pub fn surface_tint_color(self, surface_tint_color: Color) -> AlertDialog

Dart AlertDialog(surfaceTintColor:).

Source

pub fn semantic_label(self, semantic_label: impl Into<String>) -> AlertDialog

Dart AlertDialog(semanticLabel:).

Source

pub fn inset_padding(self, inset_padding: EdgeInsets) -> AlertDialog

Dart AlertDialog(insetPadding:).

Source

pub fn clip_behavior(self, clip_behavior: Clip) -> AlertDialog

Dart AlertDialog(clipBehavior:).

Source

pub fn shape(self, shape: impl Into<ShapeBorderRef>) -> AlertDialog

Dart AlertDialog(shape:).

Source

pub fn alignment(self, alignment: AlignmentGeometry) -> AlertDialog

Dart AlertDialog(alignment:).

Source

pub fn constraints(self, constraints: BoxConstraints) -> AlertDialog

Dart AlertDialog(constraints:).

Source

pub fn scrollable(self, scrollable: bool) -> AlertDialog

Dart AlertDialog(scrollable:).

Source

pub fn scroll_controller( self, scroll_controller: ScrollControllerRef, ) -> AlertDialog

Dart AlertDialog.adaptive(scrollController:); a dialog made by new ignores it.

Source

pub fn action_scroll_controller( self, action_scroll_controller: ScrollControllerRef, ) -> AlertDialog

Dart AlertDialog.adaptive(actionScrollController:); a dialog made by new ignores it.

Source

pub fn inset_animation_duration( self, inset_animation_duration: Duration, ) -> AlertDialog

Dart AlertDialog.adaptive(insetAnimationDuration:); a dialog made by new ignores it.

Source

pub fn inset_animation_curve( self, inset_animation_curve: Rc<dyn Curve>, ) -> AlertDialog

Dart AlertDialog.adaptive(insetAnimationCurve:); a dialog made by new ignores it.

Trait Implementations§

Source§

impl Debug for AlertDialog

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AlertDialog

Source§

fn default() -> AlertDialog

Returns the “default value” for a type. Read more
Source§

impl StatelessWidget for AlertDialog

Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef

Describes the part of the user interface represented by this widget. Read more
Source§

fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s debugFillProperties: the properties a dump shows for this widget, in Dart’s order. Dart’s Widget base only sets the dense tree style, which the framework does.
Source§

fn debug_check_constructor(&self)

Dart’s constructor asserts that relate two or more arguments. Read more
Source§

fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>

Dart’s this is PreferredSizeWidget: a widget that implements PreferredSizeWidget answers with itself, which is what a parent asking an erased child for its preferred size reads.

Auto Trait Implementations§

§

impl !RefUnwindSafe for AlertDialog

§

impl !Send for AlertDialog

§

impl !Sync for AlertDialog

§

impl !UnwindSafe for AlertDialog

§

impl Forget for AlertDialog

§

impl Freeze for AlertDialog
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const RcInner<dyn Widget> is !null: Freeze, PhantomData<RcInner<dyn Widget>>: Freeze, &'static dyn ColorExtension: Freeze, *const RcInner<dyn ColorExtension> is !null: Freeze, PhantomData<RcInner<dyn ColorExtension>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, PhantomData<String>: Freeze, *const RcInner<Paint> is !null: Freeze, PhantomData<RcInner<Paint>>: Freeze, PhantomData<Shadow>: Freeze, PhantomData<FontFeature>: Freeze, PhantomData<FontVariation>: Freeze, PhantomData<Rc<dyn Widget>>: Freeze, *const RcInner<dyn ShapeBorder> is !null: Freeze, PhantomData<RcInner<dyn ShapeBorder>>: Freeze, NonZero<u32>: Freeze, &'static ScrollControllerVTable: Freeze, *const RcInner<Keep> is !null: Freeze, PhantomData<RcInner<Keep>>: Freeze, *const RcInner<dyn Curve> is !null: Freeze, PhantomData<RcInner<dyn Curve>>: Freeze,

§

impl Move for AlertDialog

§

impl Unpin for AlertDialog
where Rc<dyn Key>: Unpin, Rc<dyn Widget>: Unpin, &'static dyn ColorExtension: Unpin, Rc<dyn ColorExtension>: Unpin, *const u8 is !null: Unpin, Rc<Paint>: Unpin, Rc<dyn ShapeBorder>: Unpin, NonZero<u32>: Unpin, &'static ScrollControllerVTable: Unpin, Rc<Keep>: Unpin, Rc<dyn Curve>: Unpin,

§

impl UnsafeUnpin for AlertDialog
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, *const RcInner<dyn Widget> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Widget>>: UnsafeUnpin, &'static dyn ColorExtension: UnsafeUnpin, *const RcInner<dyn ColorExtension> is !null: UnsafeUnpin, PhantomData<RcInner<dyn ColorExtension>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, PhantomData<String>: UnsafeUnpin, *const RcInner<Paint> is !null: UnsafeUnpin, PhantomData<RcInner<Paint>>: UnsafeUnpin, PhantomData<Shadow>: UnsafeUnpin, PhantomData<FontFeature>: UnsafeUnpin, PhantomData<FontVariation>: UnsafeUnpin, PhantomData<Rc<dyn Widget>>: UnsafeUnpin, *const RcInner<dyn ShapeBorder> is !null: UnsafeUnpin, PhantomData<RcInner<dyn ShapeBorder>>: UnsafeUnpin, NonZeroU32Inner: UnsafeUnpin, &'static ScrollControllerVTable: UnsafeUnpin, *const RcInner<Keep> is !null: UnsafeUnpin, PhantomData<RcInner<Keep>>: UnsafeUnpin, *const RcInner<dyn Curve> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Curve>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<W> IntoWidget<StatelessKind> for W
where W: StatelessWidget,

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>