pub struct OutlinedButton { /* private fields */ }Expand description
A Material Design “Outlined Button”; essentially a TextButton
with an outlined border.
Outlined buttons are medium-emphasis buttons. They contain actions that are important, but they aren’t the primary action in an app.
An outlined button is a label child displayed on a (zero
elevation) Material widget. The label’s Text and Icon
widgets are displayed in the style’s
ButtonStyle::foreground_color and the outline’s weight and color
are defined by ButtonStyle::side. The button reacts to touches
by filling with the style’s ButtonStyle::overlay_color.
The outlined button’s default style is defined by
default_style_of. The style of this outline button
can be overridden with its style parameter. The style of all text buttons in a subtree can
be overridden with the OutlinedButtonTheme and the style of all of the outlined buttons
in an app can be overridden with the Theme’s ThemeData::outlined_button_theme property.
Unlike TextButton or ElevatedButton, outline buttons have a
default ButtonStyle::side which defines the appearance of the
outline. Because the default side is non-null, it
unconditionally overrides the shape’s OutlinedBorder::side. In
other words, to specify an outlined button’s shape and the
appearance of its outline, both the ButtonStyle::shape and
ButtonStyle::side properties must be specified.
The static style_from method is a convenient way to create a
outlined button ButtonStyle from simple values.
See also:
ElevatedButton, a filled button whose material elevates when pressed.FilledButton, a filled button that doesn’t elevate when pressed.FilledButton::tonal, a filled button variant that uses a secondary fill color.TextButton, a button with no outline or fill color.- https://material.io/design/components/buttons.html
- https://m3.material.io/components/buttons
Implementations§
Source§impl OutlinedButton
impl OutlinedButton
Sourcepub fn new<K>(
on_pressed: Option<Listener>,
child: Option<impl IntoWidget<K>>,
) -> OutlinedButton
pub fn new<K>( on_pressed: Option<Listener>, child: Option<impl IntoWidget<K>>, ) -> OutlinedButton
Create an OutlinedButton.
Sourcepub fn key(self, key: KeyRef) -> OutlinedButton
pub fn key(self, key: KeyRef) -> OutlinedButton
Dart OutlinedButton(key:).
Sourcepub fn on_long_press(self, on_long_press: Listener) -> OutlinedButton
pub fn on_long_press(self, on_long_press: Listener) -> OutlinedButton
Dart OutlinedButton(onLongPress:).
Sourcepub fn on_hover(self, on_hover: ValueChanged<bool>) -> OutlinedButton
pub fn on_hover(self, on_hover: ValueChanged<bool>) -> OutlinedButton
Dart OutlinedButton(onHover:).
Sourcepub fn on_focus_change(
self,
on_focus_change: ValueChanged<bool>,
) -> OutlinedButton
pub fn on_focus_change( self, on_focus_change: ValueChanged<bool>, ) -> OutlinedButton
Dart OutlinedButton(onFocusChange:).
Sourcepub fn style(self, style: ButtonStyle) -> OutlinedButton
pub fn style(self, style: ButtonStyle) -> OutlinedButton
Dart OutlinedButton(style:).
Sourcepub fn focus_node(self, focus_node: FocusNodeRef) -> OutlinedButton
pub fn focus_node(self, focus_node: FocusNodeRef) -> OutlinedButton
Dart OutlinedButton(focusNode:).
Sourcepub fn autofocus(self, autofocus: bool) -> OutlinedButton
pub fn autofocus(self, autofocus: bool) -> OutlinedButton
Dart OutlinedButton(autofocus:).
Sourcepub fn clip_behavior(self, clip_behavior: Clip) -> OutlinedButton
pub fn clip_behavior(self, clip_behavior: Clip) -> OutlinedButton
Dart OutlinedButton(clipBehavior:).
Sourcepub fn states_controller(
self,
states_controller: Ref<WidgetStatesController>,
) -> OutlinedButton
pub fn states_controller( self, states_controller: Ref<WidgetStatesController>, ) -> OutlinedButton
Dart OutlinedButton(statesController:).
Sourcepub fn icon<K>(
on_pressed: Option<Listener>,
label: impl IntoWidget<K>,
) -> OutlinedButtonIcon
pub fn icon<K>( on_pressed: Option<Listener>, label: impl IntoWidget<K>, ) -> OutlinedButtonIcon
Create an outlined button from a pair of widgets that serve as the button’s
icon and label.
The icon and label are arranged in a row and padded by 12 logical pixels at the start, and 16 at the end, with an 8 pixel gap in between.
If icon is null, this constructor will create an outlined
button that doesn’t display an icon.
The alignment of the icon within the button is set by
icon_alignment; see IconAlignment.
Sourcepub fn style_from() -> OutlinedButtonStyleFromBuilder
pub fn style_from() -> OutlinedButtonStyleFromBuilder
A static convenience method that constructs an outlined 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.
The background_color and disabled_background_color colors are
used to create a WidgetStateProperty ButtonStyle::background_color.
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.
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.
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 shape and outline for an
OutlinedButton, one could write:
OutlinedButton::new(on_pressed, Text::new("Seasons of Love")).style(
OutlinedButton::style_from()
.shape(StadiumBorder::new(BorderSide::NONE))
.side(BorderSide { width: 2.0, color: Colors::GREEN.primary(), ..BorderSide::default() })
.build(),
)Trait Implementations§
Source§impl ButtonStyleButton for OutlinedButton
impl ButtonStyleButton for OutlinedButton
Source§fn default_style_of(
&self,
app: &mut App,
context: BuildContext,
) -> Box<dyn ButtonStyleGetters>
fn default_style_of( &self, app: &mut App, context: BuildContext, ) -> Box<dyn ButtonStyleGetters>
Defines the button’s default appearance.
With the exception of ButtonStyle::side, which defines the
outline, and ButtonStyle::padding, the returned style is the
same as for TextButton.
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 and is transparent by default.
All of the ButtonStyle’s defaults appear below. In this list
“Theme.foo” is shorthand for Theme::of(app, 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 color of the ButtonStyle::text_style is not used, the
ButtonStyle::foreground_color is used instead.
§Material 2 defaults
textStyle- Theme.textTheme.buttonbackgroundColor- transparentforegroundColor- disabled - Theme.colorScheme.onSurface(0.38)
- others - Theme.colorScheme.primary
overlayColor- hovered - Theme.colorScheme.primary(0.08)
- focused or pressed - Theme.colorScheme.primary(0.12)
shadowColor- Theme.shadowColorelevation- 0paddingdefault 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)
minimumSize- Size(64, 36)fixedSize- nullmaximumSize- Size.infiniteside- BorderSide(width: 1, color: Theme.colorScheme.onSurface(0.12))shape- RoundedRectangleBorder(borderRadius: BorderRadius.circular(4))mouseCursor- WidgetStateMouseCursor.adaptiveClickablevisualDensity- theme.visualDensitytapTargetSize- theme.materialTapTargetSizeanimationDuration- kThemeChangeDurationenableFeedback- truealignment- Alignment.centersplashFactory- InkRipple.splashFactory
§Material 3 defaults
If ThemeData::use_material3 is set to true the following defaults will
be used:
textStyle- Theme.textTheme.labelLargebackgroundColor- transparentforegroundColor- disabled - Theme.colorScheme.onSurface(0.38)
- others - Theme.colorScheme.primary
overlayColor- hovered - Theme.colorScheme.primary(0.08)
- focused or pressed - Theme.colorScheme.primary(0.1)
- others - null
shadowColor- Colors.transparent,surfaceTintColor- nullelevation- 0paddingdefault 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)
minimumSize- Size(64, 40)fixedSize- nullmaximumSize- Size.infiniteside- disabled - BorderSide(color: Theme.colorScheme.onSurface(0.12))
- others - BorderSide(color: Theme.colorScheme.outline)
shape- StadiumBorder()mouseCursor- WidgetStateMouseCursor.adaptiveClickablevisualDensity- theme.visualDensitytapTargetSize- theme.materialTapTargetSizeanimationDuration- kThemeChangeDurationenableFeedback- truealignment- Alignment.centersplashFactory- Theme.splashFactory
For the OutlinedButton::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>
fn theme_style_of( &self, app: &mut App, context: BuildContext, ) -> Option<ButtonStyle>
Source§impl Debug for OutlinedButton
impl Debug for OutlinedButton
Source§impl StatefulWidget for OutlinedButton
impl StatefulWidget for OutlinedButton
Source§type State = ButtonStyleState<OutlinedButton>
type State = ButtonStyleState<OutlinedButton>
Source§fn debug_fill_properties(
&self,
app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( &self, app: &App, properties: &mut DiagnosticPropertiesBuilder, )
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<OutlinedButton>
fn create_state(&self) -> ButtonStyleState<OutlinedButton>
Source§fn as_preferred_size_widget(
&self,
) -> Option<&(dyn PreferredSizeWidget + 'static)>
fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
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 OutlinedButton
impl !Send for OutlinedButton
impl !Sync for OutlinedButton
impl !UnwindSafe for OutlinedButton
impl Forget for OutlinedButton
impl Freeze for OutlinedButtonwhere
*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 OutlinedButton
impl Unpin for OutlinedButtonwhere
Rc<dyn Key>: Unpin,
Rc<dyn Fn(&mut App)>: Unpin,
NonZero<u32>: Unpin,
*const (): Unpin,
Rc<dyn Fn(&mut App, bool)>: Unpin,
Rc<dyn WidgetStateProperty<Option<TextStyle>>>: Unpin,
Rc<dyn WidgetStateProperty<Option<Color>>>: Unpin,
Rc<dyn WidgetStateProperty<Option<f64>>>: Unpin,
Rc<dyn WidgetStateProperty<Option<EdgeInsetsGeometry>>>: Unpin,
Rc<dyn WidgetStateProperty<Option<Size>>>: Unpin,
Rc<dyn WidgetStateProperty<Option<BorderSide>>>: Unpin,
Rc<dyn WidgetStateProperty<Option<OutlinedBorderRef>>>: Unpin,
Rc<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>>: Unpin,
Rc<dyn InteractiveInkFeatureFactory>: Unpin,
Rc<dyn Fn(&mut App, AnyElement, &HashSet<WidgetState>, Option<Rc<dyn Widget>>) -> Rc<dyn Widget>>: Unpin,
&'static FocusNodeVTable: Unpin,
Rc<Keep>: Unpin,
*const u8 is !null: Unpin,
Rc<dyn Widget>: Unpin,
impl UnsafeUnpin for OutlinedButtonwhere
*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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.