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>See Widget::key.
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: boolWhether 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: AxisThe direction along which the buttons are rendered.
Defaults to Axis::Horizontal.
vertical_direction: VerticalDirectionIf 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
impl ToggleButtons
Sourcepub fn new(children: Vec<WidgetRef>, is_selected: Vec<bool>) -> ToggleButtons
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.
Sourcepub fn key(self, key: KeyRef) -> ToggleButtons
pub fn key(self, key: KeyRef) -> ToggleButtons
Dart ToggleButtons(key:).
Sourcepub fn on_pressed(
self,
on_pressed: impl Fn(&mut App, usize) + 'static,
) -> ToggleButtons
pub fn on_pressed( self, on_pressed: impl Fn(&mut App, usize) + 'static, ) -> ToggleButtons
Dart ToggleButtons(onPressed:).
Sourcepub fn mouse_cursor(
self,
mouse_cursor: impl Into<MouseCursorRef>,
) -> ToggleButtons
pub fn mouse_cursor( self, mouse_cursor: impl Into<MouseCursorRef>, ) -> ToggleButtons
Dart ToggleButtons(mouseCursor:).
Sourcepub fn tap_target_size(
self,
tap_target_size: MaterialTapTargetSize,
) -> ToggleButtons
pub fn tap_target_size( self, tap_target_size: MaterialTapTargetSize, ) -> ToggleButtons
Dart ToggleButtons(tapTargetSize:).
Sourcepub fn text_style(self, text_style: TextStyle) -> ToggleButtons
pub fn text_style(self, text_style: TextStyle) -> ToggleButtons
Dart ToggleButtons(textStyle:).
Sourcepub fn constraints(self, constraints: BoxConstraints) -> ToggleButtons
pub fn constraints(self, constraints: BoxConstraints) -> ToggleButtons
Dart ToggleButtons(constraints:).
Sourcepub fn color(self, color: Color) -> ToggleButtons
pub fn color(self, color: Color) -> ToggleButtons
Dart ToggleButtons(color:).
Sourcepub fn selected_color(self, selected_color: Color) -> ToggleButtons
pub fn selected_color(self, selected_color: Color) -> ToggleButtons
Dart ToggleButtons(selectedColor:).
Sourcepub fn disabled_color(self, disabled_color: Color) -> ToggleButtons
pub fn disabled_color(self, disabled_color: Color) -> ToggleButtons
Dart ToggleButtons(disabledColor:).
Sourcepub fn fill_color(self, fill_color: impl Into<AnyColor>) -> ToggleButtons
pub fn fill_color(self, fill_color: impl Into<AnyColor>) -> ToggleButtons
Dart ToggleButtons(fillColor:).
Sourcepub fn focus_color(self, focus_color: Color) -> ToggleButtons
pub fn focus_color(self, focus_color: Color) -> ToggleButtons
Dart ToggleButtons(focusColor:).
Sourcepub fn highlight_color(self, highlight_color: Color) -> ToggleButtons
pub fn highlight_color(self, highlight_color: Color) -> ToggleButtons
Dart ToggleButtons(highlightColor:).
Sourcepub fn hover_color(self, hover_color: Color) -> ToggleButtons
pub fn hover_color(self, hover_color: Color) -> ToggleButtons
Dart ToggleButtons(hoverColor:).
Sourcepub fn splash_color(self, splash_color: Color) -> ToggleButtons
pub fn splash_color(self, splash_color: Color) -> ToggleButtons
Dart ToggleButtons(splashColor:).
Sourcepub fn focus_nodes(self, focus_nodes: Vec<FocusNodeRef>) -> ToggleButtons
pub fn focus_nodes(self, focus_nodes: Vec<FocusNodeRef>) -> ToggleButtons
Dart ToggleButtons(focusNodes:).
Sourcepub fn render_border(self, render_border: bool) -> ToggleButtons
pub fn render_border(self, render_border: bool) -> ToggleButtons
Dart ToggleButtons(renderBorder:).
Sourcepub fn border_color(self, border_color: Color) -> ToggleButtons
pub fn border_color(self, border_color: Color) -> ToggleButtons
Dart ToggleButtons(borderColor:).
Sourcepub fn selected_border_color(
self,
selected_border_color: Color,
) -> ToggleButtons
pub fn selected_border_color( self, selected_border_color: Color, ) -> ToggleButtons
Dart ToggleButtons(selectedBorderColor:).
Sourcepub fn disabled_border_color(
self,
disabled_border_color: Color,
) -> ToggleButtons
pub fn disabled_border_color( self, disabled_border_color: Color, ) -> ToggleButtons
Dart ToggleButtons(disabledBorderColor:).
Sourcepub fn border_radius(self, border_radius: BorderRadius) -> ToggleButtons
pub fn border_radius(self, border_radius: BorderRadius) -> ToggleButtons
Dart ToggleButtons(borderRadius:).
Sourcepub fn border_width(self, border_width: f64) -> ToggleButtons
pub fn border_width(self, border_width: f64) -> ToggleButtons
Dart ToggleButtons(borderWidth:).
Sourcepub fn direction(self, direction: Axis) -> ToggleButtons
pub fn direction(self, direction: Axis) -> ToggleButtons
Dart ToggleButtons(direction:).
Sourcepub fn vertical_direction(
self,
vertical_direction: VerticalDirection,
) -> ToggleButtons
pub fn vertical_direction( self, vertical_direction: VerticalDirection, ) -> ToggleButtons
Dart ToggleButtons(verticalDirection:).
Trait Implementations§
Source§impl Debug for ToggleButtons
impl Debug for ToggleButtons
Source§impl StatelessWidget for ToggleButtons
impl StatelessWidget for ToggleButtons
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 debug_check_constructor(&self)
fn debug_check_constructor(&self)
Source§fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef
fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef
Source§fn as_preferred_size_widget(
&self,
) -> Option<&(dyn PreferredSizeWidget + 'static)>
fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>
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 ToggleButtonswhere
*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
impl UnsafeUnpin for ToggleButtonswhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<Rc<dyn Widget>>: UnsafeUnpin,
PhantomData<bool>: UnsafeUnpin,
*const RcInner<dyn Fn(&mut App, usize)> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Fn(&mut App, usize)>>: UnsafeUnpin,
*const RcInner<dyn MouseCursor> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn MouseCursor>>: UnsafeUnpin,
&'static dyn ColorExtension: UnsafeUnpin,
*const RcInner<dyn ColorExtension> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn ColorExtension>>: 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<Retained<AnyFocusNode>>: 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<StatelessKind> for Wwhere
W: StatelessWidget,
impl<W> IntoWidget<StatelessKind> for Wwhere
W: StatelessWidget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.