pub struct Checkbox {Show 21 fields
pub key: Option<KeyRef>,
pub value: Option<bool>,
pub on_changed: Option<ValueChanged<Option<bool>>>,
pub mouse_cursor: Option<MouseCursorRef>,
pub active_color: Option<Color>,
pub fill_color: Option<WidgetStatePropertyRef<Option<Color>>>,
pub check_color: Option<Color>,
pub tristate: bool,
pub material_tap_target_size: Option<MaterialTapTargetSize>,
pub visual_density: Option<VisualDensity>,
pub focus_color: Option<Color>,
pub hover_color: Option<Color>,
pub overlay_color: Option<WidgetStatePropertyRef<Option<Color>>>,
pub splash_radius: Option<f64>,
pub focus_node: Option<FocusNodeRef>,
pub autofocus: bool,
pub shape: Option<OutlinedBorderRef>,
pub side: Option<AnyBorderSide>,
pub is_error: bool,
pub semantic_label: Option<String>,
pub mark_insets: Option<EdgeInsets>,
/* private fields */
}Expand description
A Material Design checkbox.
The checkbox itself does not maintain any state. Instead, when the state of
the checkbox changes, the widget calls the on_changed callback. Most
widgets that use a checkbox will listen for the on_changed callback
and rebuild the checkbox with a new value to update the visual appearance
of the checkbox.
The checkbox can optionally display three values - true, false, and null -
if tristate is true. When value is null a dash is
displayed. By default tristate is false and the checkbox’s
value must be true or false.
Requires one of its ancestors to be a Material widget.
See also:
CheckboxListTile, which combines this widget with aListTileso that you can give the checkbox a label.Switch, a widget with semantics similar toCheckbox.Radio, for selecting among a set of explicit values.Slider, for selecting a value in a range.- https://material.io/design/components/selection-controls.html#checkboxes
- https://material.io/design/components/lists.html#types
Fields§
§key: Option<KeyRef>§value: Option<bool>Whether this checkbox is checked.
When tristate is true, a value of null corresponds to the mixed
state. When tristate is false, this value must not be null.
on_changed: Option<ValueChanged<Option<bool>>>Called when the value of the checkbox should change.
The checkbox passes the new value to the callback but does not actually change state until the parent widget rebuilds the checkbox with the new value.
If this callback is null, the checkbox will be displayed as disabled and will not respond to input gestures.
When the checkbox is tapped, if tristate is false (the default)
then the on_changed callback will be applied to !value. If
tristate is true this callback cycle from false to true to null.
The callback provided to on_changed should update the state of
the parent StatefulWidget using the State::set_state method, so that the parent
gets rebuilt.
mouse_cursor: Option<MouseCursorRef>The cursor for a mouse pointer when it enters or is hovering over the widget.
If mouse_cursor is a WidgetStateMouseCursor,
WidgetStateProperty::resolve is used for the following WidgetStates:
When value is null and tristate is true,
WidgetState::Selected is included as a state.
If this property is null, the value of CheckboxThemeData::mouse_cursor is used.
If that is also null, WidgetStateMouseCursor::adaptive_clickable is used.
active_color: Option<Color>The color to use when this checkbox is checked.
Defaults to ColorScheme::secondary.
If fill_color returns a non-null color in the
WidgetState::Selected state, it will be used instead of this color.
fill_color: Option<WidgetStatePropertyRef<Option<Color>>>The color that fills the checkbox, in all WidgetStates.
Resolves in the following states:
If null, then the value of active_color is used in the selected
state. If that is also null, the value of CheckboxThemeData::fill_color
is used. If that is also null, then ThemeData::disabled_color is used in
the disabled state, ColorScheme::secondary is used in the
selected state, and ThemeData::unselected_widget_color is used in the
default state.
check_color: Option<Color>The color to use for the check icon when this checkbox is checked.
If null, then the value of CheckboxThemeData::check_color is used. If
that is also null, then Color(0xFFFFFFFF) is used.
tristate: boolIf true the checkbox’s value can be true, false, or null.
Checkbox displays a dash when its value is null.
When a tri-state checkbox (tristate is true) is tapped, its
on_changed callback will be applied to true if the current value
is false, to null if value is true, and to false if value is null (i.e. it cycles
through false => true => null => false when tapped).
If tristate is false (the default), value must not be null.
material_tap_target_size: Option<MaterialTapTargetSize>Configures the minimum size of the tap target.
If null, then the value of CheckboxThemeData::material_tap_target_size is
used. If that is also null, then the value of
ThemeData::material_tap_target_size is used.
See also:
MaterialTapTargetSize, for a description of how this affects tap targets.
visual_density: Option<VisualDensity>Defines how compact the checkbox’s layout will be.
If null, then the value of CheckboxThemeData::visual_density is used. If
that is also null and if ThemeData::use_material3 is false, then the
value of ThemeData::visual_density is used. Otherwise, the default value
is VisualDensity::STANDARD.
See also:
ThemeData::visual_density, which specifies thevisual_densityfor all widgets within aTheme.
focus_color: Option<Color>The color for the checkbox’s Material when it has the input focus.
If overlay_color returns a non-null color in the
WidgetState::Focused state, it will be used instead.
If null, then the value of CheckboxThemeData::overlay_color is used in the
focused state. If that is also null, then the value of
ThemeData::focus_color is used.
hover_color: Option<Color>The color for the checkbox’s Material when a pointer is hovering over it.
If overlay_color returns a non-null color in the
WidgetState::Hovered state, it will be used instead.
If null, then the value of CheckboxThemeData::overlay_color is used in the
hovered state. If that is also null, then the value of
ThemeData::hover_color is used.
overlay_color: Option<WidgetStatePropertyRef<Option<Color>>>The color for the checkbox’s Material.
Resolves in the following states:
If null, then the value of active_color with alpha
K_RADIAL_REACTION_ALPHA, focus_color and
hover_color is used in the pressed, focused and hovered state.
If that is also null, the value of CheckboxThemeData::overlay_color is used. If
that is also null, then the value of ColorScheme::secondary with alpha
K_RADIAL_REACTION_ALPHA, ThemeData::focus_color and ThemeData::hover_color
is used in the pressed, focused and hovered state.
splash_radius: Option<f64>The splash radius of the circular Material ink response.
If null, then the value of CheckboxThemeData::splash_radius is used. If
that is also null, then K_RADIAL_REACTION_RADIUS is used.
focus_node: Option<FocusNodeRef>An optional focus node to use as the focus node for this widget.
autofocus: boolTrue if this widget will be selected as the initial focus when no other node in its scope is currently focused.
shape: Option<OutlinedBorderRef>The shape of the checkbox’s Material.
If this property is null then the ambient CheckboxThemeData::shape
is used. If that’s null then the shape will be a RoundedRectangleBorder
with a circular corner radius of 1.0 in Material 2, and 2.0 in Material 3.
side: Option<AnyBorderSide>The color and width of the checkbox’s border.
This property can be a WidgetStateBorderSide that can
specify different border color and widths depending on the
checkbox’s state.
Resolves in the following states:
WidgetState::Pressed.WidgetState::Selected.WidgetState::Hovered.WidgetState::Focused.WidgetState::Disabled.WidgetState::Error.
If this property is not a WidgetStateBorderSide and it is
non-null, then it is only rendered when the checkbox’s value is
false. The difference in interpretation is for backwards
compatibility.
If this property is null, then the ambient CheckboxThemeData::side is
used. If that is also null, then the side will be width 2.
is_error: boolTrue if this checkbox wants to show an error state.
The checkbox will have different default container color and check color when
this is true. This is only used when ThemeData::use_material3 is set to true.
Defaults to false.
semantic_label: Option<String>The semantic label for the checkbox that will be announced by screen readers.
This is announced by assistive technologies (e.g TalkBack/VoiceOver).
This label does not show in the UI.
mark_insets: Option<EdgeInsets>The insets applied around the check mark when the checkbox is checked or in its indeterminate (tristate) state.
This insets the check mark inward; the size of the checkbox box itself
is not affected. The check mark and its stroke shrink to fit the
remaining space, so the mark stays proportional. Its size is the smaller
of the remaining width and height, and it is centered in the remaining
space, so an inset on one axis also shrinks it on the other. For example,
EdgeInsets::only(9.0, 0.0, 0.0, 0.0) draws a half-size mark centered in the right
half of the box.
On iOS and macOS, when using Checkbox::adaptive, this property has no
effect, because the checkbox delegates to CupertinoCheckbox, which does
not support insets.
Must be non-negative. If the horizontal or vertical insets are greater than or equal to the checkbox size, the check mark or indeterminate dash is not painted.
If null, CheckboxThemeData::mark_insets is used. If that is also null,
it defaults to EdgeInsets::ZERO and the check mark renders at full size.
Implementations§
Source§impl Checkbox
impl Checkbox
Sourcepub fn new(
value: Option<bool>,
on_changed: Option<ValueChanged<Option<bool>>>,
) -> Checkbox
pub fn new( value: Option<bool>, on_changed: Option<ValueChanged<Option<bool>>>, ) -> Checkbox
Creates a Material Design checkbox.
The checkbox itself does not maintain any state. Instead, when the state of
the checkbox changes, the widget calls the on_changed callback.
Most widgets that use a checkbox will listen for the on_changed
callback and rebuild the checkbox with a new value to update the
visual appearance of the checkbox.
The following arguments are required:
value, which determines whether the checkbox is checked. Thevaluecan only be null iftristateis true.on_changed, which is called when the value of the checkbox should change. It can be set to null to disable the checkbox.
Sourcepub fn adaptive(
value: Option<bool>,
on_changed: Option<ValueChanged<Option<bool>>>,
) -> Checkbox
pub fn adaptive( value: Option<bool>, on_changed: Option<ValueChanged<Option<bool>>>, ) -> Checkbox
Creates an adaptive Checkbox based on whether the target platform is iOS
or macOS, following Material design’s
Cross-platform guidelines.
On iOS and macOS, this constructor creates a CupertinoCheckbox, which has
matching functionality and presentation as Material checkboxes, and are the
graphics expected on iOS. On other platforms, this creates a Material
design Checkbox.
If a CupertinoCheckbox is created, the following parameters are ignored:
fill_color, hover_color,
overlay_color, splash_radius,
material_tap_target_size,
visual_density, is_error,
mark_insets. However, shape and
side will still affect the CupertinoCheckbox and should be
handled if native fidelity is important.
The target platform is based on the current Theme: ThemeData::platform.
Sourcepub fn mouse_cursor(self, mouse_cursor: MouseCursorRef) -> Checkbox
pub fn mouse_cursor(self, mouse_cursor: MouseCursorRef) -> Checkbox
Dart Checkbox(mouseCursor:).
Sourcepub fn active_color(self, active_color: Color) -> Checkbox
pub fn active_color(self, active_color: Color) -> Checkbox
Dart Checkbox(activeColor:).
Sourcepub fn fill_color(
self,
fill_color: WidgetStatePropertyRef<Option<Color>>,
) -> Checkbox
pub fn fill_color( self, fill_color: WidgetStatePropertyRef<Option<Color>>, ) -> Checkbox
Dart Checkbox(fillColor:).
Sourcepub fn check_color(self, check_color: Color) -> Checkbox
pub fn check_color(self, check_color: Color) -> Checkbox
Dart Checkbox(checkColor:).
Sourcepub fn focus_color(self, focus_color: Color) -> Checkbox
pub fn focus_color(self, focus_color: Color) -> Checkbox
Dart Checkbox(focusColor:).
Sourcepub fn hover_color(self, hover_color: Color) -> Checkbox
pub fn hover_color(self, hover_color: Color) -> Checkbox
Dart Checkbox(hoverColor:).
Sourcepub fn overlay_color(
self,
overlay_color: WidgetStatePropertyRef<Option<Color>>,
) -> Checkbox
pub fn overlay_color( self, overlay_color: WidgetStatePropertyRef<Option<Color>>, ) -> Checkbox
Dart Checkbox(overlayColor:).
Sourcepub fn splash_radius(self, splash_radius: f64) -> Checkbox
pub fn splash_radius(self, splash_radius: f64) -> Checkbox
Dart Checkbox(splashRadius:).
Sourcepub fn material_tap_target_size(
self,
material_tap_target_size: MaterialTapTargetSize,
) -> Checkbox
pub fn material_tap_target_size( self, material_tap_target_size: MaterialTapTargetSize, ) -> Checkbox
Dart Checkbox(materialTapTargetSize:).
Sourcepub fn visual_density(self, visual_density: VisualDensity) -> Checkbox
pub fn visual_density(self, visual_density: VisualDensity) -> Checkbox
Dart Checkbox(visualDensity:).
Sourcepub fn focus_node(self, focus_node: FocusNodeRef) -> Checkbox
pub fn focus_node(self, focus_node: FocusNodeRef) -> Checkbox
Dart Checkbox(focusNode:).
Sourcepub fn shape(self, shape: impl Into<OutlinedBorderRef>) -> Checkbox
pub fn shape(self, shape: impl Into<OutlinedBorderRef>) -> Checkbox
Dart Checkbox(shape:).
Sourcepub fn side(self, side: impl Into<AnyBorderSide>) -> Checkbox
pub fn side(self, side: impl Into<AnyBorderSide>) -> Checkbox
Dart Checkbox(side:).
Sourcepub fn semantic_label(self, semantic_label: impl Into<String>) -> Checkbox
pub fn semantic_label(self, semantic_label: impl Into<String>) -> Checkbox
Dart Checkbox(semanticLabel:).
Sourcepub fn mark_insets(self, mark_insets: EdgeInsets) -> Checkbox
pub fn mark_insets(self, mark_insets: EdgeInsets) -> Checkbox
Dart Checkbox(markInsets:).
Trait Implementations§
Source§impl StatefulWidget for Checkbox
impl StatefulWidget for Checkbox
Source§type State = CheckboxState
type State = CheckboxState
Source§fn create_state(&self) -> CheckboxState
fn create_state(&self) -> CheckboxState
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 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 Checkbox
impl !Send for Checkbox
impl !Sync for Checkbox
impl !UnwindSafe for Checkbox
impl Forget for Checkbox
impl Freeze for Checkboxwhere
*const RcInner<dyn Key> is !null: Freeze,
PhantomData<RcInner<dyn Key>>: Freeze,
*const RcInner<dyn Fn(&mut App, Option<bool>)> is !null: Freeze,
PhantomData<RcInner<dyn Fn(&mut App, Option<bool>)>>: Freeze,
*const RcInner<dyn MouseCursor> is !null: Freeze,
PhantomData<RcInner<dyn MouseCursor>>: Freeze,
*const RcInner<dyn WidgetStateProperty<Option<Color>>> is !null: Freeze,
PhantomData<RcInner<dyn WidgetStateProperty<Option<Color>>>>: Freeze,
NonZero<u32>: Freeze,
&'static FocusNodeVTable: Freeze,
*const RcInner<Keep> is !null: Freeze,
PhantomData<RcInner<Keep>>: Freeze,
*const RcInner<dyn OutlinedBorder> is !null: Freeze,
PhantomData<RcInner<dyn OutlinedBorder>>: Freeze,
*const RcInner<dyn BorderSideExtension> is !null: Freeze,
PhantomData<RcInner<dyn BorderSideExtension>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
impl Move for Checkbox
impl Unpin for Checkboxwhere
Rc<dyn Key>: Unpin,
Rc<dyn Fn(&mut App, Option<bool>)>: Unpin,
Rc<dyn MouseCursor>: Unpin,
Rc<dyn WidgetStateProperty<Option<Color>>>: Unpin,
NonZero<u32>: Unpin,
&'static FocusNodeVTable: Unpin,
Rc<Keep>: Unpin,
Rc<dyn OutlinedBorder>: Unpin,
Rc<dyn BorderSideExtension>: Unpin,
*const u8 is !null: Unpin,
impl UnsafeUnpin for Checkboxwhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
*const RcInner<dyn Fn(&mut App, Option<bool>)> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Fn(&mut App, Option<bool>)>>: UnsafeUnpin,
*const RcInner<dyn MouseCursor> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn MouseCursor>>: UnsafeUnpin,
*const RcInner<dyn WidgetStateProperty<Option<Color>>> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn WidgetStateProperty<Option<Color>>>>: UnsafeUnpin,
NonZeroU32Inner: UnsafeUnpin,
&'static FocusNodeVTable: UnsafeUnpin,
*const RcInner<Keep> is !null: UnsafeUnpin,
PhantomData<RcInner<Keep>>: UnsafeUnpin,
*const RcInner<dyn OutlinedBorder> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn OutlinedBorder>>: UnsafeUnpin,
*const RcInner<dyn BorderSideExtension> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn BorderSideExtension>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: 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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.