Skip to main content

FloatingActionButton

Struct FloatingActionButton 

Source
pub struct FloatingActionButton {
Show 27 fields pub key: Option<KeyRef>, pub child: Option<WidgetRef>, pub tooltip: Option<String>, pub foreground_color: Option<Color>, pub background_color: Option<Color>, pub focus_color: Option<Color>, pub hover_color: Option<Color>, pub splash_color: Option<Color>, pub hero_tag: Option<Rc<dyn AnyEq>>, pub on_pressed: Option<Listener>, pub mouse_cursor: Option<MouseCursorRef>, pub elevation: Option<f64>, pub focus_elevation: Option<f64>, pub hover_elevation: Option<f64>, pub highlight_elevation: Option<f64>, pub disabled_elevation: Option<f64>, pub mini: bool, pub shape: Option<ShapeBorderRef>, pub clip_behavior: Clip, pub is_extended: bool, pub focus_node: Option<FocusNodeRef>, pub autofocus: bool, pub material_tap_target_size: Option<MaterialTapTargetSize>, pub enable_feedback: Option<bool>, pub extended_icon_label_spacing: Option<f64>, pub extended_padding: Option<EdgeInsetsGeometry>, pub extended_text_style: Option<TextStyle>, /* private fields */
}
Expand description

A Material Design floating action button.

A floating action button is a circular icon button that hovers over content to promote a primary action in the application. Floating action buttons are most commonly used in the Scaffold::floating_action_button field.

Use at most a single floating action button per screen. Floating action buttons should be used for positive actions such as “create”, “share”, or “navigate”. (If more than one floating action button is used within a Route, then make sure that each button has a unique hero_tag, otherwise an exception will be thrown.)

If the on_pressed callback is null, then the button will be disabled and will not react to touch. It is highly discouraged to disable a floating action button as there is no indication to the user that the button is disabled. Consider changing the background_color if disabling the floating action button.

See also:

Fields§

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

The widget below this widget in the tree.

Typically an Icon.

§tooltip: Option<String>

Text that describes the action that will occur when the button is pressed.

This text is displayed when the user long-presses on the button and is used for accessibility.

§foreground_color: Option<Color>

The default foreground color for icons and text within the button.

If this property is null, then the ambient FloatingActionButtonThemeData::foreground_color is used. If that property is also null, then the ColorScheme::on_primary_container color of ThemeData::color_scheme is used. If ThemeData::use_material3 is set to false, then the ColorScheme::on_secondary color of ThemeData::color_scheme is used.

§background_color: Option<Color>

The button’s background color.

If this property is null, then the ambient FloatingActionButtonThemeData::background_color is used. If that property is also null, then the ColorScheme::primary_container color of ThemeData::color_scheme is used. If ThemeData::use_material3 is set to false, then the ColorScheme::secondary color of ThemeData::color_scheme is used.

§focus_color: Option<Color>

The color to use for filling the button when the button has input focus.

In Material3, defaults to ColorScheme::on_primary_container with opacity 0.1. In Material 2, it defaults to ThemeData::focus_color for the current theme.

§hover_color: Option<Color>

The color to use for filling the button when the button has a pointer hovering over it.

Defaults to ThemeData::hover_color for the current theme in Material 2. In Material 3, defaults to ColorScheme::on_primary_container with opacity 0.08.

§splash_color: Option<Color>

The splash color for this FloatingActionButton’s InkWell.

If null, FloatingActionButtonThemeData::splash_color is used, if that is null, ThemeData::splash_color is used in Material 2; ColorScheme::on_primary_container with opacity 0.1 is used in Material 3.

§hero_tag: Option<Rc<dyn AnyEq>>

The tag to apply to the button’s Hero widget.

Defaults to a tag that matches other floating action buttons.

Set this to null explicitly if you don’t want the floating action button to have a hero tag.

If this is not explicitly set, then there can only be one FloatingActionButton per route (that is, per screen), since otherwise there would be a tag conflict (multiple heroes on one route can’t have the same tag). The Material Design specification recommends only using one floating action button per screen.

§on_pressed: Option<Listener>

The callback that is called when the button is tapped or otherwise activated.

If this is set to null, the button will be disabled.

§mouse_cursor: Option<MouseCursorRef>

The cursor for a mouse pointer when it enters or is hovering over the button.

If this property is null, FloatingActionButtonThemeData::mouse_cursor is used. If that is null, WidgetStateMouseCursor::adaptive_clickable will be used.

§elevation: Option<f64>

The z-coordinate at which to place this button relative to its parent.

This controls the size of the shadow below the floating action button.

Defaults to 6, the appropriate elevation for floating action buttons. The value is always non-negative.

See also:

§focus_elevation: Option<f64>

The z-coordinate at which to place this button relative to its parent when the button has the input focus.

This controls the size of the shadow below the floating action button.

Defaults to 8, the appropriate elevation for floating action buttons while they have focus. The value is always non-negative.

See also:

§hover_elevation: Option<f64>

The z-coordinate at which to place this button relative to its parent when the button is enabled and has a pointer hovering over it.

This controls the size of the shadow below the floating action button.

Defaults to 8, the appropriate elevation for floating action buttons while they have a pointer hovering over them. The value is always non-negative.

See also:

§highlight_elevation: Option<f64>

The z-coordinate at which to place this button relative to its parent when the user is touching the button.

This controls the size of the shadow below the floating action button.

Defaults to 12, the appropriate elevation for floating action buttons while they are being touched. The value is always non-negative.

See also:

§disabled_elevation: Option<f64>

The z-coordinate at which to place this button when the button is disabled (on_pressed is null).

This controls the size of the shadow below the floating action button.

Defaults to the same value as elevation. Setting this to zero makes the floating action button work similar to an ElevatedButton but the titular “floating” effect is lost. The value is always non-negative.

See also:

§mini: bool

Controls the size of this button.

By default, floating action buttons are non-mini and have a height and width of 56.0 logical pixels. Mini floating action buttons have a height and width of 40.0 logical pixels with a layout width and height of 48.0 logical pixels. (The extra 4 pixels of padding on each side are added as a result of the floating action button having MaterialTapTargetSize::Padded set on the underlying RawMaterialButton::material_tap_target_size.)

§shape: Option<ShapeBorderRef>

The shape of the button’s Material.

The button’s highlight and splash are clipped to this shape. If the button has an elevation, then its drop shadow is defined by this shape as well.

§clip_behavior: Clip

The content will be clipped (or not) according to this option.

Defaults to Clip::None.

§is_extended: bool

True if this is an “extended” floating action button.

Typically “extended” buttons have a StadiumBorder shape and have been created with the FloatingActionButton::extended constructor.

The Scaffold animates the appearance of ordinary floating action buttons with scale and rotation transitions. Extended floating action buttons are scaled and faded in.

§focus_node: Option<FocusNodeRef>

An optional focus node to use as the focus node for this widget.

See Focus::focus_node.

§autofocus: bool

True if this widget will be selected as the initial focus when no other node in its scope is currently focused.

See Focus::autofocus.

§material_tap_target_size: Option<MaterialTapTargetSize>

Configures the minimum size of the tap target.

Defaults to ThemeData::material_tap_target_size.

See also:

§enable_feedback: Option<bool>

Whether detected gestures should provide acoustic and/or haptic feedback.

For example, on Android a tap will produce a clicking sound and a long-press will produce a short vibration, when feedback is enabled.

If null, FloatingActionButtonThemeData::enable_feedback is used. If both are null, then default value is true.

See also:

  • Feedback for providing platform-specific feedback to certain actions.
§extended_icon_label_spacing: Option<f64>

The spacing between the icon and the label for an extended FloatingActionButton.

If null, FloatingActionButtonThemeData::extended_icon_label_spacing is used. If that is also null, the default is 8.0.

§extended_padding: Option<EdgeInsetsGeometry>

The padding for an extended FloatingActionButton’s content.

If null, FloatingActionButtonThemeData::extended_padding is used. If that is also null, the default is EdgeInsetsDirectional.only(start: 16.0, end: 20.0) if an icon is provided, and EdgeInsetsDirectional.only(start: 20.0, end: 20.0) if not.

§extended_text_style: Option<TextStyle>

The text style for an extended FloatingActionButton’s label.

If null, FloatingActionButtonThemeData::extended_text_style is used. If that is also null, then TextTheme::label_large with a letter spacing of 1.2 is used.

Implementations§

Source§

impl FloatingActionButton

Source

pub fn new(on_pressed: Option<Listener>) -> FloatingActionButton

Creates a circular floating action button.

The elevation, highlight_elevation, and disabled_elevation parameters, if specified, must be non-negative.

Source

pub fn small(on_pressed: Option<Listener>) -> FloatingActionButton

Creates a small circular floating action button.

This constructor overrides the default size constraints of the floating action button.

The elevation, focus_elevation, hover_elevation, highlight_elevation, and disabled_elevation parameters, if specified, must be non-negative.

Source

pub fn large(on_pressed: Option<Listener>) -> FloatingActionButton

Creates a large circular floating action button.

This constructor overrides the default size constraints of the floating action button.

The elevation, focus_elevation, hover_elevation, highlight_elevation, and disabled_elevation parameters, if specified, must be non-negative.

Source

pub fn extended<K>( on_pressed: Option<Listener>, label: impl IntoWidget<K>, ) -> FloatingActionButton

Creates a wider StadiumBorder-shaped floating action button with an optional icon and a label.

The elevation, highlight_elevation, and disabled_elevation parameters, if specified, must be non-negative.

See also:

Source

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

Dart FloatingActionButton(key:).

Source

pub fn child<K>(self, child: impl IntoWidget<K>) -> FloatingActionButton

Dart FloatingActionButton(child:).

Source

pub fn tooltip(self, tooltip: impl Into<String>) -> FloatingActionButton

Dart FloatingActionButton(tooltip:).

Source

pub fn foreground_color(self, foreground_color: Color) -> FloatingActionButton

Dart FloatingActionButton(foregroundColor:).

Source

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

Dart FloatingActionButton(backgroundColor:).

Source

pub fn focus_color(self, focus_color: Color) -> FloatingActionButton

Dart FloatingActionButton(focusColor:).

Source

pub fn hover_color(self, hover_color: Color) -> FloatingActionButton

Dart FloatingActionButton(hoverColor:).

Source

pub fn splash_color(self, splash_color: Color) -> FloatingActionButton

Dart FloatingActionButton(splashColor:).

Source

pub fn hero_tag(self, hero_tag: Option<Rc<dyn AnyEq>>) -> FloatingActionButton

Dart FloatingActionButton(heroTag:); None is Dart’s explicit heroTag: null.

Source

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

Dart FloatingActionButton(elevation:).

Source

pub fn focus_elevation(self, focus_elevation: f64) -> FloatingActionButton

Dart FloatingActionButton(focusElevation:).

Source

pub fn hover_elevation(self, hover_elevation: f64) -> FloatingActionButton

Dart FloatingActionButton(hoverElevation:).

Source

pub fn highlight_elevation( self, highlight_elevation: f64, ) -> FloatingActionButton

Dart FloatingActionButton(highlightElevation:).

Source

pub fn disabled_elevation(self, disabled_elevation: f64) -> FloatingActionButton

Dart FloatingActionButton(disabledElevation:).

Source

pub fn mouse_cursor( self, mouse_cursor: impl Into<MouseCursorRef>, ) -> FloatingActionButton

Dart FloatingActionButton(mouseCursor:).

Source

pub fn mini(self, mini: bool) -> FloatingActionButton

Dart FloatingActionButton(mini:), an argument of the unnamed constructor only, which picks the small type when it is true.

Source

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

Dart FloatingActionButton(shape:).

Source

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

Dart FloatingActionButton(clipBehavior:).

Source

pub fn is_extended(self, is_extended: bool) -> FloatingActionButton

Dart FloatingActionButton(isExtended:) and FloatingActionButton.extended(isExtended:).

Source

pub fn focus_node(self, focus_node: FocusNodeRef) -> FloatingActionButton

Dart FloatingActionButton(focusNode:).

Source

pub fn autofocus(self, autofocus: bool) -> FloatingActionButton

Dart FloatingActionButton(autofocus:).

Source

pub fn material_tap_target_size( self, material_tap_target_size: MaterialTapTargetSize, ) -> FloatingActionButton

Dart FloatingActionButton(materialTapTargetSize:).

Source

pub fn enable_feedback(self, enable_feedback: bool) -> FloatingActionButton

Dart FloatingActionButton(enableFeedback:).

Source

pub fn extended_icon_label_spacing( self, extended_icon_label_spacing: f64, ) -> FloatingActionButton

Dart FloatingActionButton.extended(extendedIconLabelSpacing:).

Source

pub fn extended_padding( self, extended_padding: impl Into<EdgeInsetsGeometry>, ) -> FloatingActionButton

Dart FloatingActionButton.extended(extendedPadding:).

Source

pub fn extended_text_style( self, extended_text_style: TextStyle, ) -> FloatingActionButton

Dart FloatingActionButton.extended(extendedTextStyle:).

Source

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

Dart FloatingActionButton.extended(icon:), which the constructor stores as child.

Trait Implementations§

Source§

impl Debug for FloatingActionButton

Source§

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

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

impl StatelessWidget for FloatingActionButton

Source§

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

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 build(&self, app: &mut App, context: BuildContext) -> WidgetRef

Describes the part of the user interface represented by this widget. Read more
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 FloatingActionButton

§

impl !Send for FloatingActionButton

§

impl !Sync for FloatingActionButton

§

impl !UnwindSafe for FloatingActionButton

§

impl Forget for FloatingActionButton

§

impl Freeze for FloatingActionButton
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, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const RcInner<dyn AnyEq> is !null: Freeze, PhantomData<RcInner<dyn AnyEq>>: Freeze, *const RcInner<dyn Fn(&mut App)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App)>>: Freeze, NonZero<u32>: Freeze, *const (): Freeze, *const RcInner<dyn MouseCursor> is !null: Freeze, PhantomData<RcInner<dyn MouseCursor>>: Freeze, *const RcInner<dyn ShapeBorder> is !null: Freeze, PhantomData<RcInner<dyn ShapeBorder>>: Freeze, &'static FocusNodeVTable: Freeze, *const RcInner<Keep> is !null: Freeze, PhantomData<RcInner<Keep>>: Freeze, &'static dyn ColorExtension: Freeze, *const RcInner<dyn ColorExtension> is !null: Freeze, PhantomData<RcInner<dyn ColorExtension>>: Freeze, PhantomData<String>: Freeze, *const RcInner<Paint> is !null: Freeze, PhantomData<RcInner<Paint>>: Freeze, PhantomData<Shadow>: Freeze, PhantomData<FontFeature>: Freeze, PhantomData<FontVariation>: Freeze,

§

impl Move for FloatingActionButton

§

impl Unpin for FloatingActionButton
where Rc<dyn Key>: Unpin, Rc<dyn Widget>: Unpin, *const u8 is !null: Unpin, Rc<dyn AnyEq>: Unpin, Rc<dyn Fn(&mut App)>: Unpin, NonZero<u32>: Unpin, *const (): Unpin, Rc<dyn MouseCursor>: Unpin, Rc<dyn ShapeBorder>: Unpin, &'static FocusNodeVTable: Unpin, Rc<Keep>: Unpin, &'static dyn ColorExtension: Unpin, Rc<dyn ColorExtension>: Unpin, Rc<Paint>: Unpin,

§

impl UnsafeUnpin for FloatingActionButton
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, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const RcInner<dyn AnyEq> is !null: UnsafeUnpin, PhantomData<RcInner<dyn AnyEq>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App)>>: UnsafeUnpin, NonZeroU32Inner: UnsafeUnpin, *const (): UnsafeUnpin, *const RcInner<dyn MouseCursor> is !null: UnsafeUnpin, PhantomData<RcInner<dyn MouseCursor>>: UnsafeUnpin, *const RcInner<dyn ShapeBorder> is !null: UnsafeUnpin, PhantomData<RcInner<dyn ShapeBorder>>: UnsafeUnpin, &'static FocusNodeVTable: UnsafeUnpin, *const RcInner<Keep> is !null: UnsafeUnpin, PhantomData<RcInner<Keep>>: UnsafeUnpin, &'static dyn ColorExtension: UnsafeUnpin, *const RcInner<dyn ColorExtension> is !null: UnsafeUnpin, PhantomData<RcInner<dyn ColorExtension>>: UnsafeUnpin, PhantomData<String>: UnsafeUnpin, *const RcInner<Paint> is !null: UnsafeUnpin, PhantomData<RcInner<Paint>>: UnsafeUnpin, PhantomData<Shadow>: UnsafeUnpin, PhantomData<FontFeature>: UnsafeUnpin, PhantomData<FontVariation>: 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>