Skip to main content

Checkbox

Struct Checkbox 

Source
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:

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: bool

If 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:

§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 the visual_density for all widgets within a Theme.
§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: bool

True 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:

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: bool

True 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

Source

pub const WIDTH: f64 = 18.0

The width of a checkbox widget.

Source

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. The value can only be null if tristate is true.
  • on_changed, which is called when the value of the checkbox should change. It can be set to null to disable the checkbox.
Source

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.

Source

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

Dart Checkbox(key:).

Source

pub fn tristate(self, tristate: bool) -> Checkbox

Dart Checkbox(tristate:).

Source

pub fn mouse_cursor(self, mouse_cursor: MouseCursorRef) -> Checkbox

Dart Checkbox(mouseCursor:).

Source

pub fn active_color(self, active_color: Color) -> Checkbox

Dart Checkbox(activeColor:).

Source

pub fn fill_color( self, fill_color: WidgetStatePropertyRef<Option<Color>>, ) -> Checkbox

Dart Checkbox(fillColor:).

Source

pub fn check_color(self, check_color: Color) -> Checkbox

Dart Checkbox(checkColor:).

Source

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

Dart Checkbox(focusColor:).

Source

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

Dart Checkbox(hoverColor:).

Source

pub fn overlay_color( self, overlay_color: WidgetStatePropertyRef<Option<Color>>, ) -> Checkbox

Dart Checkbox(overlayColor:).

Source

pub fn splash_radius(self, splash_radius: f64) -> Checkbox

Dart Checkbox(splashRadius:).

Source

pub fn material_tap_target_size( self, material_tap_target_size: MaterialTapTargetSize, ) -> Checkbox

Dart Checkbox(materialTapTargetSize:).

Source

pub fn visual_density(self, visual_density: VisualDensity) -> Checkbox

Dart Checkbox(visualDensity:).

Source

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

Dart Checkbox(focusNode:).

Source

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

Dart Checkbox(autofocus:).

Source

pub fn shape(self, shape: impl Into<OutlinedBorderRef>) -> Checkbox

Dart Checkbox(shape:).

Source

pub fn side(self, side: impl Into<AnyBorderSide>) -> Checkbox

Dart Checkbox(side:).

Source

pub fn is_error(self, is_error: bool) -> Checkbox

Dart Checkbox(isError:).

Source

pub fn semantic_label(self, semantic_label: impl Into<String>) -> Checkbox

Dart Checkbox(semanticLabel:).

Source

pub fn mark_insets(self, mark_insets: EdgeInsets) -> Checkbox

Dart Checkbox(markInsets:).

Trait Implementations§

Source§

impl Clone for Checkbox

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Checkbox

Source§

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

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

impl StatefulWidget for Checkbox

Source§

type State = CheckboxState

The state this widget creates.
Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn debug_check_constructor(&self)

Source§

fn create_state(&self) -> CheckboxState

Creates the mutable state for this widget at a given location in the tree. Read more
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 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 Checkbox

§

impl !Send for Checkbox

§

impl !Sync for Checkbox

§

impl !UnwindSafe for Checkbox

§

impl Forget for Checkbox

§

impl Freeze for Checkbox
where *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 Checkbox
where 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 Checkbox
where *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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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>