Skip to main content

FilledButton

Struct FilledButton 

Source
pub struct FilledButton { /* private fields */ }
Expand description

A Material Design filled button.

Filled buttons have the most visual impact after the FloatingActionButton, and should be used for important, final actions that complete a flow, like Save, Join now, or Confirm.

A filled button is a label child displayed on a Material widget. The label’s Text and Icon widgets are displayed in style’s ButtonStyle::foreground_color and the button’s filled background is the ButtonStyle::background_color.

The filled button’s default style is defined by default_style_of. The style of this filled button can be overridden with its style parameter. The style of all filled buttons in a subtree can be overridden with the FilledButtonTheme, and the style of all of the filled buttons in an app can be overridden with the Theme’s ThemeData::filled_button_theme property.

The static style_from method is a convenient way to create a filled button ButtonStyle from simple values.

If on_pressed and on_long_press callbacks are null, then the button will be disabled.

To create a ‘filled tonal’ button, use FilledButton::tonal.

§Visual density effects

The button’s appearance is affected by the VisualDensity from the enclosing Theme or from its style. Visual density adjusts the ButtonStyle::padding and ButtonStyle::minimum_size to accommodate different UI densities across platforms. See VisualDensity for more details on how it affects component layout and the platform-specific defaults.

See also:

Implementations§

Source§

impl FilledButton

Source

pub fn new<K>( on_pressed: Option<Listener>, child: Option<impl IntoWidget<K>>, ) -> FilledButton

Create a FilledButton.

Source

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

Create a filled button from icon and label.

The icon and label are arranged in a row with padding at the start and end and a gap between them.

If icon is null, this constructor will create a FilledButton that doesn’t display an icon.

The alignment of the icon within the button is set by icon_alignment; see IconAlignment.

Source

pub fn tonal<K>( on_pressed: Option<Listener>, child: Option<impl IntoWidget<K>>, ) -> FilledButton

Create a tonal variant of FilledButton.

A filled tonal button is an alternative middle ground between FilledButton and OutlinedButton. They’re useful in contexts where a lower-priority button requires slightly more emphasis than an outline would give, such as “Next” in an onboarding flow.

Source

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

Create a filled tonal button from icon and label.

The icon and label are arranged in a row with padding at the start and end and a gap between them.

If icon is null, this constructor will create a FilledButton that doesn’t display an icon.

Source

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

Dart FilledButton(key:).

Source

pub fn on_long_press(self, on_long_press: Listener) -> FilledButton

Dart FilledButton(onLongPress:).

Source

pub fn on_hover(self, on_hover: ValueChanged<bool>) -> FilledButton

Dart FilledButton(onHover:).

Source

pub fn on_focus_change( self, on_focus_change: ValueChanged<bool>, ) -> FilledButton

Dart FilledButton(onFocusChange:).

Source

pub fn style(self, style: ButtonStyle) -> FilledButton

Dart FilledButton(style:).

Source

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

Dart FilledButton(focusNode:).

Source

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

Dart FilledButton(autofocus:).

Source

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

Dart FilledButton(clipBehavior:).

Source

pub fn states_controller( self, states_controller: Ref<WidgetStatesController>, ) -> FilledButton

Dart FilledButton(statesController:).

Source

pub fn style_from() -> FilledButtonStyleFromBuilder

A static convenience method that constructs a filled button ButtonStyle given simple values.

The foreground_color and disabled_foreground_color colors are used to create a WidgetStateProperty ButtonStyle::foreground_color, and a derived ButtonStyle::overlay_color if overlay_color isn’t specified.

If overlay_color is specified and its value is Colors::TRANSPARENT then the pressed/focused/hovered highlights are effectively defeated. Otherwise a WidgetStateProperty with the same opacities as the default is created.

Similarly, the enabled_mouse_cursor and disabled_mouse_cursor parameters are used to construct ButtonStyle::mouse_cursor.

The icon_color, disabled_icon_color are used to construct ButtonStyle::icon_color and icon_size is used to construct ButtonStyle::icon_size.

If icon_color is null, the button icon will use foreground_color. If foreground_color is also null, the button icon will use the default icon color.

The button’s elevations are defined relative to the elevation parameter. The disabled elevation is the same as the parameter value, elevation + 2 is used when the button is hovered or focused, and elevation + 6 is used when the button is pressed.

All of the other parameters are either used directly or used to create a WidgetStateProperty with a single value for all states.

All parameters default to null, by default this method returns a ButtonStyle that doesn’t override anything.

For example, to override the default text and icon colors for a FilledButton, as well as its overlay color, with all of the standard opacity adjustments for the pressed, focused, and hovered states, one could write:

FilledButton::new(on_pressed, Text::new("Filled button"))
    .style(FilledButton::style_from().foreground_color(Colors::GREEN.primary()).build())

or for a Filled tonal variant:

FilledButton::tonal(on_pressed, Text::new("Filled tonal button"))
    .style(FilledButton::style_from().foreground_color(Colors::GREEN.primary()).build())

Trait Implementations§

Source§

impl ButtonStyleButton for FilledButton

Source§

fn default_style_of( &self, app: &mut App, context: BuildContext, ) -> Box<dyn ButtonStyleGetters>

Defines the button’s default appearance.

The button child’s Text and Icon widgets are rendered with the ButtonStyle’s foreground color. The button’s InkWell adds the style’s overlay color when the button is focused, hovered or pressed. The button’s background color becomes its Material color.

All of the ButtonStyle’s defaults appear below. In this list “Theme.foo” is shorthand for Theme::of(context).foo. Color scheme values like “onSurface(0.38)” are shorthand for on_surface.with_opacity(0.38). WidgetStateProperty valued properties that are not followed by a sublist have the same value for all states, otherwise the values are as specified for each state, and “others” means all other states.

The “default font size” below refers to the font size specified in the default_style_of method (or 14.0 if unspecified), scaled by the MediaQuery::text_scaler_of(context).scale method. The names of the EdgeInsets constructors and EdgeInsetsGeometry::lerp have been abbreviated for readability.

The color of the ButtonStyle::text_style is not used, the ButtonStyle::foreground_color color is used instead.

  • text_style - Theme.textTheme.labelLarge
  • background_color
    • disabled - Theme.colorScheme.onSurface(0.12)
    • others - Theme.colorScheme.secondaryContainer
  • foreground_color
    • disabled - Theme.colorScheme.onSurface(0.38)
    • others - Theme.colorScheme.onSecondaryContainer
  • overlay_color
    • hovered - Theme.colorScheme.onSecondaryContainer(0.08)
    • focused or pressed - Theme.colorScheme.onSecondaryContainer(0.12)
  • shadow_color - Theme.colorScheme.shadow
  • surface_tint_color - null
  • elevation
    • disabled - 0
    • default - 0
    • hovered - 1
    • focused or pressed - 0
  • padding
    • default font size <= 14 - horizontal(16)
    • 14 < default font size <= 28 - lerp(horizontal(16), horizontal(8))
    • 28 < default font size <= 36 - lerp(horizontal(8), horizontal(4))
    • 36 < default font size - horizontal(4)
  • minimum_size - Size(64, 40)
  • fixed_size - null
  • maximum_size - Size.infinite
  • side - null
  • shape - StadiumBorder()
  • mouse_cursor - WidgetStateMouseCursor.adaptiveClickable
  • visual_density - Theme.visualDensity
  • tap_target_size - Theme.materialTapTargetSize
  • animation_duration - kThemeChangeDuration
  • enable_feedback - true
  • alignment - Alignment.center
  • splash_factory - Theme.splashFactory

The default padding values for the FilledButton::icon factory are slightly different:

  • padding
    • default font size <= 14 - start(12) end(16)
    • 14 < default font size <= 28 - lerp(start(12) end(16), horizontal(8))
    • 28 < default font size <= 36 - lerp(horizontal(8), horizontal(4))
    • 36 < default font size - horizontal(4)

The default value for side, which defines the appearance of the button’s outline, is null. That means that the outline is defined by the button shape’s OutlinedBorder::side. Typically the default value of an [OutlinedBorder]’s side is BorderSide::NONE, so an outline is not drawn.

§Material 3 defaults

If ThemeData::use_material3 is set to true the following defaults will be used:

  • text_style - Theme.textTheme.labelLarge
  • background_color
    • disabled - Theme.colorScheme.onSurface(0.12)
    • others
      • Theme.colorScheme.primary in FilledButton
      • Theme.colorScheme.secondaryContainer in FilledButton.tonal
  • foreground_color
    • disabled - Theme.colorScheme.onSurface(0.38)
    • others
      • Theme.colorScheme.onPrimary in FilledButton
      • Theme.colorScheme.onSecondaryContainer in FilledButton.tonal
  • overlay_color
    • hovered
      • Theme.colorScheme.onPrimary(0.08) in FilledButton
      • Theme.colorScheme.onSecondaryContainer(0.08) in FilledButton.tonal
    • focused or pressed
      • Theme.colorScheme.onPrimary(0.1) in FilledButton
      • Theme.colorScheme.onSecondaryContainer(0.1) in FilledButton.tonal
  • shadow_color - Theme.colorScheme.shadow
  • surface_tint_color - Colors.transparent
  • elevation
    • disabled - 0
    • default - 1
    • hovered - 3
    • focused or pressed - 1
  • padding
    • default font size <= 14 - horizontal(24)
    • 14 < default font size <= 28 - lerp(horizontal(24), horizontal(12))
    • 28 < default font size <= 36 - lerp(horizontal(12), horizontal(6))
    • 36 < default font size - horizontal(6)
  • minimum_size - Size(64, 40)
  • fixed_size - null
  • maximum_size - Size.infinite
  • side - null
  • shape - StadiumBorder()
  • mouse_cursor - WidgetStateMouseCursor.adaptiveClickable
  • visual_density - Theme.visualDensity
  • tap_target_size - Theme.materialTapTargetSize
  • animation_duration - kThemeChangeDuration
  • enable_feedback - true
  • alignment - Alignment.center
  • splash_factory - Theme.splashFactory

For the FilledButton::icon factory, the start (generally the left) value of ButtonStyle::padding is reduced from 24 to 16.

Source§

fn theme_style_of( &self, app: &mut App, context: BuildContext, ) -> Option<ButtonStyle>

Returns the FilledButtonThemeData::style of the closest FilledButtonTheme ancestor.

Source§

fn button_style_button_data(&self) -> &ButtonStyleButtonData

Source§

fn enabled(&self) -> bool

Whether the button is enabled or disabled. Read more
Source§

impl Debug for FilledButton

Source§

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

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

impl StatefulWidget for FilledButton

Source§

type State = ButtonStyleState<FilledButton>

The state this widget creates.
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 create_state(&self) -> ButtonStyleState<FilledButton>

Creates the mutable state for this widget at a given location in the tree. Read more
Source§

fn debug_check_constructor(&self)

Source§

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

Source§

fn type_name(&self) -> &'static str

See Widget::type_name. A stateful form another widget kind becomes (an animated or status transition widget) names the widget it wraps.

Auto Trait Implementations§

§

impl !RefUnwindSafe for FilledButton

§

impl !Send for FilledButton

§

impl !Sync for FilledButton

§

impl !UnwindSafe for FilledButton

§

impl Forget for FilledButton

§

impl Freeze for FilledButton
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: 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 Fn(&mut App, bool)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, bool)>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<TextStyle>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<TextStyle>>>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<Color>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<Color>>>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<f64>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<f64>>>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<EdgeInsetsGeometry>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<EdgeInsetsGeometry>>>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<Size>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<Size>>>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<BorderSide>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<BorderSide>>>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<OutlinedBorderRef>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<OutlinedBorderRef>>>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>>>: Freeze, *const RcInner<dyn InteractiveInkFeatureFactory> is !null: Freeze, PhantomData<RcInner<dyn InteractiveInkFeatureFactory>>: Freeze, *const RcInner<dyn Fn(&mut App, AnyElement, &HashSet<WidgetState>, Option<Rc<dyn Widget>>) -> Rc<dyn Widget>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, &HashSet<WidgetState>, Option<Rc<dyn Widget>>) -> Rc<dyn Widget>>>: Freeze, &'static FocusNodeVTable: Freeze, *const RcInner<Keep> is !null: Freeze, PhantomData<RcInner<Keep>>: Freeze, PhantomData<fn() -> WidgetStatesController>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const RcInner<dyn Widget> is !null: Freeze, PhantomData<RcInner<dyn Widget>>: Freeze,

§

impl Move for FilledButton

§

impl Unpin for FilledButton

§

impl UnsafeUnpin for FilledButton
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App)>>: UnsafeUnpin, NonZeroU32Inner: UnsafeUnpin, *const (): UnsafeUnpin, *const RcInner<dyn Fn(&mut App, bool)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, bool)>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<TextStyle>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<TextStyle>>>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<Color>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<Color>>>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<f64>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<f64>>>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<EdgeInsetsGeometry>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<EdgeInsetsGeometry>>>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<Size>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<Size>>>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<BorderSide>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<BorderSide>>>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<OutlinedBorderRef>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<OutlinedBorderRef>>>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>>>: UnsafeUnpin, *const RcInner<dyn InteractiveInkFeatureFactory> is !null: UnsafeUnpin, PhantomData<RcInner<dyn InteractiveInkFeatureFactory>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, AnyElement, &HashSet<WidgetState>, Option<Rc<dyn Widget>>) -> Rc<dyn Widget>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, &HashSet<WidgetState>, Option<Rc<dyn Widget>>) -> Rc<dyn Widget>>>: UnsafeUnpin, &'static FocusNodeVTable: UnsafeUnpin, *const RcInner<Keep> is !null: UnsafeUnpin, PhantomData<RcInner<Keep>>: UnsafeUnpin, PhantomData<fn() -> WidgetStatesController>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const RcInner<dyn Widget> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Widget>>: 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<StatefulKind> for W
where W: StatefulWidget,

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>