Skip to main content

ToggleButtons

Struct ToggleButtons 

Source
pub struct ToggleButtons {
Show 25 fields pub key: Option<KeyRef>, pub children: Vec<WidgetRef>, pub is_selected: Vec<bool>, pub on_pressed: Option<ValueChanged<usize>>, pub mouse_cursor: Option<MouseCursorRef>, pub tap_target_size: Option<MaterialTapTargetSize>, pub text_style: Option<TextStyle>, pub constraints: Option<BoxConstraints>, pub color: Option<Color>, pub selected_color: Option<Color>, pub disabled_color: Option<Color>, pub fill_color: Option<AnyColor>, pub focus_color: Option<Color>, pub highlight_color: Option<Color>, pub splash_color: Option<Color>, pub hover_color: Option<Color>, pub focus_nodes: Option<Vec<FocusNodeRef>>, pub render_border: bool, pub border_color: Option<Color>, pub selected_border_color: Option<Color>, pub disabled_border_color: Option<Color>, pub border_width: Option<f64>, pub border_radius: Option<BorderRadius>, pub direction: Axis, pub vertical_direction: VerticalDirection,
}
Expand description

A set of toggle buttons.

The list of children are laid out along direction. The state of each button is controlled by is_selected, which is a list of bools that determine if a button is in an unselected or selected state. They are both correlated by their index in the list. The length of is_selected has to match the length of the children list.

§Updating the button states

When the button is tapped, a on_pressed callback with the index of the pressed button is called. The app must update the selection state in response, as the buttons keep none.

§Customizing toggle buttons

Each toggle’s behavior can be configured by the on_pressed callback and is_selected list, which determines if the button is enabled or selected, and the colors and border of the buttons are set by the other fields, falling back to ToggleButtonsTheme, then to values from the overall Theme.

See also:

  • SegmentedButton, a Material 3 replacement for this widget.
  • IconButton, to create buttons that contain icons.
  • TextButton, a Material Design button without a shadow.
  • ElevatedButton, a filled button whose material elevates when pressed.
  • OutlinedButton, a button with an outlined border and no fill color.
  • https://material.io/design/components/buttons.html

Fields§

§key: Option<KeyRef>§children: Vec<WidgetRef>

The toggle button widgets.

These are typically Icon or Text widgets. The boolean selection state of each widget is defined by the corresponding is_selected list item.

The length of this list has to match the length of the is_selected list.

§is_selected: Vec<bool>

The corresponding selection state of each toggle button.

Each value in this list represents the selection state of the children widget at the same index.

The length of this list has to match the length of the children list.

§on_pressed: Option<ValueChanged<usize>>

The callback that is called when a button is tapped.

The index parameter of the callback is the index of the button that is tapped or otherwise activated.

When the callback is null, all toggle buttons will be disabled.

§mouse_cursor: Option<MouseCursorRef>

{@macro flutter.material.RawMaterialButton.mouseCursor}

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

§tap_target_size: Option<MaterialTapTargetSize>

Configures the minimum size of the area within which the buttons may be pressed.

If the tap_target_size is larger than constraints, the button will include a pad of the remaining size so that the tap target is at least as big as the tap_target_size.

Defaults to ThemeData::material_tap_target_size.

§text_style: Option<TextStyle>

The text style of children.

TextStyle::color will be ignored and substituted by color, selected_color or disabled_color depending on whether the buttons are active, selected, or disabled.

If this property is null, then ToggleButtonsThemeData::text_style is used. If that is also null, then TextTheme::body_medium is used.

§constraints: Option<BoxConstraints>

Defines the button’s size.

Typically used to constrain the button’s minimum size.

If this property is null, then ToggleButtonsThemeData::constraints is used. If that is also null, then a minimum size of 48 by 48 is used.

§color: Option<Color>

The color for descendant Text and Icon widgets if the button is enabled and not selected.

If on_pressed is not null, this color will be used for unselected children. If it is null, then ToggleButtonsThemeData::color is used. If that is also null, then ColorScheme::on_surface with an opacity of 0.87 is used.

§selected_color: Option<Color>

The color for descendant Text and Icon widgets if the button is selected.

If null, then ToggleButtonsThemeData::selected_color is used. If that is also null, then ColorScheme::primary is used.

§disabled_color: Option<Color>

The color for descendant Text and Icon widgets if the button is disabled.

If null, then ToggleButtonsThemeData::disabled_color is used. If that is also null, then ColorScheme::on_surface with an opacity of 0.38 is used.

§fill_color: Option<AnyColor>

The fill color for selected toggle buttons.

If this is null, then ToggleButtonsThemeData::fill_color is used. If that is also null, then ColorScheme::primary with an opacity of 0.12 is used.

It can be a WidgetStateColor, which then resolves in the WidgetState::Selected and WidgetState::Disabled states.

§focus_color: Option<Color>

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

If null, ToggleButtonsThemeData::focus_color is used, else ColorScheme::primary or ColorScheme::on_surface with an opacity of 0.12.

§highlight_color: Option<Color>

The highlight color for the button’s InkWell.

If null, ToggleButtonsThemeData::highlight_color is used, else ColorScheme::on_surface with an opacity of 0.16 for an unselected button.

§splash_color: Option<Color>

The splash color for the button’s InkWell.

If null, ToggleButtonsThemeData::splash_color is used, else ColorScheme::primary or ColorScheme::on_surface with an opacity of 0.16.

§hover_color: Option<Color>

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

If null, ToggleButtonsThemeData::hover_color is used, else ColorScheme::primary or ColorScheme::on_surface with an opacity of 0.04.

§focus_nodes: Option<Vec<FocusNodeRef>>

The list of FocusNodeRefs, corresponding to each toggle button.

Focus is used to determine which widget should be affected by keyboard events. The focus tree keeps track of which widget is currently focused on by the user.

If not null, the length of this list has to match the length of the children list.

§render_border: bool

Whether or not to render a border around each toggle button.

When true, a border with border_width, border_color, selected_border_color and disabled_border_color is drawn.

Defaults to true.

§border_color: Option<Color>

The border color to display when the toggle button is enabled and not selected.

If null, ToggleButtonsThemeData::border_color is used, else ColorScheme::on_surface with an opacity of 0.12.

§selected_border_color: Option<Color>

The border color to display when the toggle button is selected.

If null, ToggleButtonsThemeData::selected_border_color is used, else ColorScheme::on_surface with an opacity of 0.12.

§disabled_border_color: Option<Color>

The border color to display when the toggle button is disabled.

If null, ToggleButtonsThemeData::disabled_border_color is used, else ColorScheme::on_surface with an opacity of 0.12.

§border_width: Option<f64>

The width of the border surrounding each toggle button.

This applies to both the greater surrounding border, as well as the borders dividing each toggle button.

To render a hairline border (one physical pixel), set border_width to 0.0. If null, ToggleButtonsThemeData::border_width is used, else 1.0.

§border_radius: Option<BorderRadius>

The radii of the border’s corners.

If this property is null, then ToggleButtonsThemeData::border_radius is used. If that is also null, then BorderRadius::ZERO is used.

§direction: Axis

The direction along which the buttons are rendered.

Defaults to Axis::Horizontal.

§vertical_direction: VerticalDirection

If direction is Axis::Vertical, this property defines whether the buttons are laid out starting from the top (down) or the bottom (up).

Defaults to VerticalDirection::Down.

Implementations§

Source§

impl ToggleButtons

Source

pub fn new(children: Vec<WidgetRef>, is_selected: Vec<bool>) -> ToggleButtons

Creates a set of toggle buttons.

It displays its widgets provided in a list of children along direction. The state of each button is controlled by is_selected, which is a list of bools that determine if a button is in an unselected or selected state. They are both correlated by their index in the list. The length of is_selected has to match the length of the children list.

Source

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

Dart ToggleButtons(key:).

Source

pub fn on_pressed( self, on_pressed: impl Fn(&mut App, usize) + 'static, ) -> ToggleButtons

Dart ToggleButtons(onPressed:).

Source

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

Dart ToggleButtons(mouseCursor:).

Source

pub fn tap_target_size( self, tap_target_size: MaterialTapTargetSize, ) -> ToggleButtons

Dart ToggleButtons(tapTargetSize:).

Source

pub fn text_style(self, text_style: TextStyle) -> ToggleButtons

Dart ToggleButtons(textStyle:).

Source

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

Dart ToggleButtons(constraints:).

Source

pub fn color(self, color: Color) -> ToggleButtons

Dart ToggleButtons(color:).

Source

pub fn selected_color(self, selected_color: Color) -> ToggleButtons

Dart ToggleButtons(selectedColor:).

Source

pub fn disabled_color(self, disabled_color: Color) -> ToggleButtons

Dart ToggleButtons(disabledColor:).

Source

pub fn fill_color(self, fill_color: impl Into<AnyColor>) -> ToggleButtons

Dart ToggleButtons(fillColor:).

Source

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

Dart ToggleButtons(focusColor:).

Source

pub fn highlight_color(self, highlight_color: Color) -> ToggleButtons

Dart ToggleButtons(highlightColor:).

Source

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

Dart ToggleButtons(hoverColor:).

Source

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

Dart ToggleButtons(splashColor:).

Source

pub fn focus_nodes(self, focus_nodes: Vec<FocusNodeRef>) -> ToggleButtons

Dart ToggleButtons(focusNodes:).

Source

pub fn render_border(self, render_border: bool) -> ToggleButtons

Dart ToggleButtons(renderBorder:).

Source

pub fn border_color(self, border_color: Color) -> ToggleButtons

Dart ToggleButtons(borderColor:).

Source

pub fn selected_border_color( self, selected_border_color: Color, ) -> ToggleButtons

Dart ToggleButtons(selectedBorderColor:).

Source

pub fn disabled_border_color( self, disabled_border_color: Color, ) -> ToggleButtons

Dart ToggleButtons(disabledBorderColor:).

Source

pub fn border_radius(self, border_radius: BorderRadius) -> ToggleButtons

Dart ToggleButtons(borderRadius:).

Source

pub fn border_width(self, border_width: f64) -> ToggleButtons

Dart ToggleButtons(borderWidth:).

Source

pub fn direction(self, direction: Axis) -> ToggleButtons

Dart ToggleButtons(direction:).

Source

pub fn vertical_direction( self, vertical_direction: VerticalDirection, ) -> ToggleButtons

Dart ToggleButtons(verticalDirection:).

Trait Implementations§

Source§

impl Debug for ToggleButtons

Source§

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

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

impl StatelessWidget for ToggleButtons

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 debug_check_constructor(&self)

Dart’s constructor asserts that relate two or more arguments. Read more
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 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 ToggleButtons

§

impl !Send for ToggleButtons

§

impl !Sync for ToggleButtons

§

impl !UnwindSafe for ToggleButtons

§

impl Forget for ToggleButtons

§

impl Freeze for ToggleButtons
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const u8 is !null: Freeze, PhantomData<Rc<dyn Widget>>: Freeze, PhantomData<bool>: Freeze, *const RcInner<dyn Fn(&mut App, usize)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, usize)>>: Freeze, *const RcInner<dyn MouseCursor> is !null: Freeze, PhantomData<RcInner<dyn MouseCursor>>: Freeze, &'static dyn ColorExtension: Freeze, *const RcInner<dyn ColorExtension> is !null: Freeze, PhantomData<RcInner<dyn ColorExtension>>: 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<Retained<AnyFocusNode>>: Freeze,

§

impl Move for ToggleButtons

§

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

§

impl UnsafeUnpin for ToggleButtons

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>