Skip to main content

Radio

Struct Radio 

Source
pub struct Radio<T: Clone + PartialEq + 'static> {
Show 22 fields pub key: Option<KeyRef>, pub value: T, pub group_value: Option<T>, pub on_changed: Option<ValueChanged<Option<T>>>, pub mouse_cursor: Option<MouseCursorRef>, pub toggleable: bool, pub active_color: Option<Color>, pub fill_color: Option<WidgetStatePropertyRef<Option<Color>>>, 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 use_cupertino_checkmark_style: bool, pub group_registry: Option<RadioGroupRegistryRef<T>>, pub enabled: Option<bool>, pub background_color: Option<WidgetStatePropertyRef<Option<Color>>>, pub side: Option<AnyBorderSide>, pub inner_radius: Option<WidgetStatePropertyRef<Option<f64>>>, /* private fields */
}
Expand description

A Material Design radio button.

This widget builds a RawRadio with a material UI.

Used to select between a number of mutually exclusive values. When one radio button in a group is selected, the other radio buttons in the group cease to be selected. The values are of type T, the type parameter of the Radio class. Enums are commonly used for this purpose.

This widget typically has a RadioGroup ancestor, which takes in a RadioGroup::group_value, and the Radio under it with matching value will be selected.

Requires one of its ancestors to be a Material widget.

See also:

Fields§

§key: Option<KeyRef>§value: T

The value represented by this radio button.

§group_value: Option<T>

The currently selected value for a group of radio buttons.

This radio button is considered selected if its value matches the group_value.

This is deprecated, use RadioGroup to manage group value instead.

§on_changed: Option<ValueChanged<Option<T>>>

Called when the user selects this radio button.

The radio button passes value as a parameter to this callback. The radio button does not actually change state until the parent widget rebuilds the radio button with the new group_value.

If null, the radio button will be displayed as disabled.

The provided callback will not be invoked if this radio button is already selected and toggleable is not set to true.

If the toggleable is set to true, tapping a already selected radio will invoke this callback with null as value.

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.

This is deprecated, use RadioGroup to handle value change instead.

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

If null, the value of RadioThemeData::mouse_cursor is used. If that is also null, WidgetStateMouseCursor::adaptive_clickable is used.

§toggleable: bool

Set to true if this radio button is allowed to be returned to an indeterminate state by selecting it again when selected.

To indicate returning to an indeterminate state, RadioGroup::on_changed of the RadioGroup above the widget tree will be called with null.

If true, RadioGroup::on_changed is called with value when selected while RadioGroup::group_value != value, and with null when selected again while RadioGroup::group_value == value.

If false, RadioGroup::on_changed will be called with value when it is selected while RadioGroup::group_value != value, and only by selecting another radio button in the group (i.e. changing the value of RadioGroup::group_value) can this radio button be unselected.

The default is false.

§active_color: Option<Color>

The color to use when this radio button is selected.

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 radio button, 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, then the value of RadioThemeData::fill_color is used. If that is also null and ThemeData::use_material3 is false, 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; if ThemeData::use_material3 is true, then ColorScheme::on_surface is used in the disabled state, ColorScheme::primary is used in the selected state and ColorScheme::on_surface_variant is used in the default state.

§material_tap_target_size: Option<MaterialTapTargetSize>

Configures the minimum size of the tap target.

If null, then the value of RadioThemeData::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 radio’s layout will be.

If null, then the value of RadioThemeData::visual_density is used. If that is also null, then the value of ThemeData::visual_density is used.

See also:

  • ThemeData::visual_density, which specifies the visual_density for all widgets within a Theme.
§focus_color: Option<Color>

The color for the radio’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 RadioThemeData::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 radio’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 RadioThemeData::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 radio’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 RadioThemeData::overlay_color is used. If that is also null, then in Material 2, 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. In Material3, the default values are:

  • selected
    • pressed - Theme.colorScheme.onSurface(0.1)
    • hovered - Theme.colorScheme.primary(0.08)
    • focused - Theme.colorScheme.primary(0.1)
  • pressed - Theme.colorScheme.primary(0.1)
  • hovered - Theme.colorScheme.onSurface(0.08)
  • focused - Theme.colorScheme.onSurface(0.1)
§splash_radius: Option<f64>

The splash radius of the circular Material ink response.

If null, then the value of RadioThemeData::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.

If one is not supplied, then one will be automatically allocated, owned, and managed by this widget. The widget will be focusable even if a focus_node is not supplied. If supplied, the given focus_node will be hosted by this widget, but not owned.

§autofocus: bool

True if this widget will be selected as the initial focus when no other node in its scope is currently focused.

§use_cupertino_checkmark_style: bool

Controls whether the checkmark style is used in an iOS-style radio.

Only usable under the Radio::adaptive constructor. If set to true, on Apple platforms the radio button will appear as an iOS styled checkmark. Controls the CupertinoRadio through CupertinoRadio::use_checkmark_style.

Defaults to false.

§group_registry: Option<RadioGroupRegistryRef<T>>

The registry this radio registers to.

Unless provided, the BuildContext will be used to look up the ancestor RadioGroupRegistry.

§enabled: Option<bool>

Whether this widget is interactive.

If not provided, this widget will be interactable if one of the following is true:

If this is set to true, one of the above condition must also be true. Otherwise, an assertion error is thrown.

§background_color: Option<WidgetStatePropertyRef<Option<Color>>>

The color of the background of the radio button, in all WidgetStates.

Resolves in the following states:

If null, then the ambient RadioThemeData::background_color is used. If that is also null the default value is transparent in all states.

§side: Option<AnyBorderSide>

The side for the circular border of the radio button, in all WidgetStates.

This property can be a BorderSide or a WidgetStateBorderSide to leverage widget state resolution.

Resolves in the following states:

If null, then the ambient RadioThemeData::side is used. If that is also null, the default value is a border using the fill color.

§inner_radius: Option<WidgetStatePropertyRef<Option<f64>>>

The radius of the inner circle of the radio button, in all WidgetStates.

Resolves in the following states:

If null, then the ambient RadioThemeData::inner_radius is used. If that is also null, the default value is 4.5 in all states.

Implementations§

Source§

impl<T: Clone + PartialEq + 'static> Radio<T>

Source

pub fn new(value: T) -> Radio<T>

Creates a Material Design radio button.

This widget typically has a RadioGroup ancestor, which takes in a RadioGroup::group_value, and the Radio under it with matching value will be selected.

The value is required.

Source

pub fn adaptive(value: T) -> Radio<T>

Creates an adaptive Radio 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 CupertinoRadio, which has matching functionality and presentation as Material checkboxes, and are the graphics expected on iOS. On other platforms, this creates a Material design Radio.

If a CupertinoRadio is created, the following parameters are ignored: mouse_cursor, fill_color, hover_color, overlay_color, splash_radius, material_tap_target_size, visual_density.

use_cupertino_checkmark_style is used only if a CupertinoRadio is created.

The target platform is based on the current Theme: ThemeData::platform.

Source

pub fn key(self, key: KeyRef) -> Radio<T>

Dart Radio(key:).

Source

pub fn group_value(self, group_value: T) -> Radio<T>

👎Deprecated:

Use a RadioGroup ancestor to manage group value instead. This feature was deprecated after v3.32.0-0.0.pre.

Dart Radio(groupValue:).

Source

pub fn on_changed(self, on_changed: ValueChanged<Option<T>>) -> Radio<T>

👎Deprecated:

Use RadioGroup to handle value change instead. This feature was deprecated after v3.32.0-0.0.pre.

Dart Radio(onChanged:).

Source

pub fn mouse_cursor(self, mouse_cursor: MouseCursorRef) -> Radio<T>

Dart Radio(mouseCursor:).

Source

pub fn toggleable(self, toggleable: bool) -> Radio<T>

Dart Radio(toggleable:).

Source

pub fn active_color(self, active_color: Color) -> Radio<T>

Dart Radio(activeColor:).

Source

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

Dart Radio(fillColor:).

Source

pub fn focus_color(self, focus_color: Color) -> Radio<T>

Dart Radio(focusColor:).

Source

pub fn hover_color(self, hover_color: Color) -> Radio<T>

Dart Radio(hoverColor:).

Source

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

Dart Radio(overlayColor:).

Source

pub fn splash_radius(self, splash_radius: f64) -> Radio<T>

Dart Radio(splashRadius:).

Source

pub fn material_tap_target_size( self, material_tap_target_size: MaterialTapTargetSize, ) -> Radio<T>

Dart Radio(materialTapTargetSize:).

Source

pub fn visual_density(self, visual_density: VisualDensity) -> Radio<T>

Dart Radio(visualDensity:).

Source

pub fn focus_node(self, focus_node: FocusNodeRef) -> Radio<T>

Dart Radio(focusNode:).

Source

pub fn autofocus(self, autofocus: bool) -> Radio<T>

Dart Radio(autofocus:).

Source

pub fn use_cupertino_checkmark_style( self, use_cupertino_checkmark_style: bool, ) -> Radio<T>

Dart Radio.adaptive(useCupertinoCheckmarkStyle:); only a radio made by Radio::adaptive reads it.

Source

pub fn enabled(self, enabled: bool) -> Radio<T>

Dart Radio(enabled:).

Source

pub fn group_registry( self, group_registry: RadioGroupRegistryRef<T>, ) -> Radio<T>

Dart Radio(groupRegistry:).

Source

pub fn background_color( self, background_color: WidgetStatePropertyRef<Option<Color>>, ) -> Radio<T>

Dart Radio(backgroundColor:).

Source

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

Dart Radio(side:).

Source

pub fn inner_radius( self, inner_radius: WidgetStatePropertyRef<Option<f64>>, ) -> Radio<T>

Dart Radio(innerRadius:).

Trait Implementations§

Source§

impl<T: Clone + Clone + PartialEq + 'static> Clone for Radio<T>

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<T: Clone + PartialEq + 'static> Debug for Radio<T>

Source§

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

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

impl<T: Clone + PartialEq + 'static> StatefulWidget for Radio<T>

Source§

type State = RadioState<T>

The state this widget creates.
Source§

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

Source§

fn create_state(&self) -> RadioState<T>

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

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<T> !RefUnwindSafe for Radio<T>

§

impl<T> !Send for Radio<T>

§

impl<T> !Sync for Radio<T>

§

impl<T> !UnwindSafe for Radio<T>

§

impl<T> Forget for Radio<T>

§

impl<T> Freeze for Radio<T>
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, T: Freeze, *const RcInner<dyn Fn(&mut App, Option<T>)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, Option<T>)>>: 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, &'static RadioGroupRegistryVTable<T>: Freeze, *const RcInner<dyn BorderSideExtension> is !null: Freeze, PhantomData<RcInner<dyn BorderSideExtension>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<f64>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<f64>>>>: Freeze,

§

impl<T> Move for Radio<T>

§

impl<T> Unpin for Radio<T>
where T: Unpin, Rc<dyn Key>: Unpin, Rc<dyn Fn(&mut App, Option<T>)>: Unpin, Rc<dyn MouseCursor>: Unpin, Rc<dyn WidgetStateProperty<Option<Color>>>: Unpin, NonZero<u32>: Unpin, &'static FocusNodeVTable: Unpin, Rc<Keep>: Unpin, &'static RadioGroupRegistryVTable<T>: Unpin, Rc<dyn BorderSideExtension>: Unpin, Rc<dyn WidgetStateProperty<Option<f64>>>: Unpin,

§

impl<T> UnsafeUnpin for Radio<T>
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, T: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, Option<T>)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, Option<T>)>>: 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, &'static RadioGroupRegistryVTable<T>: UnsafeUnpin, *const RcInner<dyn BorderSideExtension> is !null: UnsafeUnpin, PhantomData<RcInner<dyn BorderSideExtension>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<f64>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<f64>>>>: 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>