pub trait ToggleableStateMixin: TickerProviderStateMixin + TickerProviderObject {
Show 21 methods
// Required methods
fn toggleable_data(
self: Handle<Self>,
app: &App,
) -> &ToggleableStateMixinData;
fn toggleable_data_mut(
self: Handle<Self>,
app: &mut App,
) -> &mut ToggleableStateMixinData;
fn on_changed(
self: Handle<Self>,
app: &App,
) -> Option<ValueChanged<Option<bool>>>;
fn value(self: Handle<Self>, app: &App) -> Option<bool>;
fn tristate(self: Handle<Self>, app: &App) -> bool;
// Provided methods
fn as_toggleable_state(self: Handle<Self>) -> AnyToggleableState { ... }
fn position_controller(
self: Handle<Self>,
app: &App,
) -> Handle<AnimationController> { ... }
fn position(self: Handle<Self>, app: &App) -> &Ref<CurvedAnimation> { ... }
fn reaction_controller(
self: Handle<Self>,
app: &App,
) -> Handle<AnimationController> { ... }
fn reaction(self: Handle<Self>, app: &App) -> &Ref<CurvedAnimation> { ... }
fn reaction_hover_fade(
self: Handle<Self>,
app: &App,
) -> &Ref<CurvedAnimation> { ... }
fn reaction_focus_fade(
self: Handle<Self>,
app: &App,
) -> &Ref<CurvedAnimation> { ... }
fn reaction_animation_duration(
self: Handle<Self>,
app: &App,
) -> Option<Duration> { ... }
fn is_interactive(self: Handle<Self>, app: &App) -> bool { ... }
fn init_state(self: Handle<Self>, app: &mut App) { ... }
fn animate_to_value(self: Handle<Self>, app: &mut App) { ... }
fn dispose(self: Handle<Self>, app: &mut App) { ... }
fn down_position(self: Handle<Self>, app: &App) -> Option<Offset> { ... }
fn states(self: Handle<Self>, app: &App) -> WidgetStates { ... }
fn build_toggleable(
self: Handle<Self>,
app: &mut App,
focus_node: Option<FocusNodeRef>,
on_focus_change: Option<ValueChanged<bool>>,
autofocus: bool,
mouse_cursor: Option<WidgetStatePropertyRef<MouseCursorRef>>,
size: Size,
painter: impl CustomPainter,
) -> WidgetRef { ... }
fn build_toggleable_with_child(
self: Handle<Self>,
app: &mut App,
focus_node: Option<FocusNodeRef>,
on_focus_change: Option<ValueChanged<bool>>,
autofocus: bool,
mouse_cursor: Option<WidgetStatePropertyRef<MouseCursorRef>>,
child: WidgetRef,
) -> WidgetRef { ... }
}Expand description
A mixin for StatefulWidgets that implement toggleable controls with toggle animations
(e.g. Switches, CupertinoSwitches, Checkboxes, CupertinoCheckboxes, Radios, and
CupertinoRadios).
The mixin implements the logic for toggling the control (e.g. when tapped) and provides a
series of animation controllers to transition the control from one state to another. It
does not have any opinion about the visual representation of the toggleable widget. The
visuals are defined by a CustomPainter passed to the
build_toggleable. State objects using this
mixin should call that method from their build method.
The state holds a ToggleableStateMixinData under the field toggleable, and its
init_state and dispose call this mixin’s where Dart’s super calls reach it:
init_state first, then dispose followed by
TickerProviderStateMixin::dispose.
Required Methods§
Sourcefn toggleable_data(self: Handle<Self>, app: &App) -> &ToggleableStateMixinData
fn toggleable_data(self: Handle<Self>, app: &App) -> &ToggleableStateMixinData
Mixin field access.
Sourcefn toggleable_data_mut(
self: Handle<Self>,
app: &mut App,
) -> &mut ToggleableStateMixinData
fn toggleable_data_mut( self: Handle<Self>, app: &mut App, ) -> &mut ToggleableStateMixinData
See toggleable_data.
Sourcefn on_changed(
self: Handle<Self>,
app: &App,
) -> Option<ValueChanged<Option<bool>>>
fn on_changed( self: Handle<Self>, app: &App, ) -> Option<ValueChanged<Option<bool>>>
Called when the control changes value.
If the control is tapped, on_changed is called immediately with
the new value.
The control is considered interactive (see is_interactive) if
this callback is non-null. If the callback is null, then the control is disabled, and
non-interactive. A disabled checkbox, for example, is displayed using a grey color and
its value cannot be changed.
Sourcefn value(self: Handle<Self>, app: &App) -> Option<bool>
fn value(self: Handle<Self>, app: &App) -> Option<bool>
False if this control is “inactive” (not checked, off, or unselected).
If value is true then the control “active” (checked, on, or selected). If tristate is true and value is null, then the control is considered to be in its third or “indeterminate” state.
When the value changes, this object starts the
position_controller and position
animations to animate the visual appearance of the control to the new value.
Provided Methods§
Sourcefn as_toggleable_state(self: Handle<Self>) -> AnyToggleableState
fn as_toggleable_state(self: Handle<Self>) -> AnyToggleableState
This state as the erased AnyToggleableState — what to pass where a Dart API takes a
ToggleableStateMixin.
Sourcefn position_controller(
self: Handle<Self>,
app: &App,
) -> Handle<AnimationController>
fn position_controller( self: Handle<Self>, app: &App, ) -> Handle<AnimationController>
Used by subclasses to manipulate the visual value of the control.
Some controls respond to user input by updating their visual value. For example, the
thumb of a switch moves from one position to another when dragged. These controls
manipulate this animation controller to update their position and
eventually trigger an on_changed callback when the animation
reaches either 0.0 or 1.0.
Sourcefn position(self: Handle<Self>, app: &App) -> &Ref<CurvedAnimation>
fn position(self: Handle<Self>, app: &App) -> &Ref<CurvedAnimation>
The visual value of the control.
When the control is inactive, the value is false and this animation
has the value 0.0. When the control is active, the value is either true or tristate is
true and the value is null. When the control is active the animation has a value of
1.0. When the control is changing from inactive to active (or vice versa),
value is the target value and this animation gradually updates from
0.0 to 1.0 (or vice versa).
Sourcefn reaction_controller(
self: Handle<Self>,
app: &App,
) -> Handle<AnimationController>
fn reaction_controller( self: Handle<Self>, app: &App, ) -> Handle<AnimationController>
Used by subclasses to control the radial reaction animation.
Some controls have a radial ink reaction to user input. This animation controller can be used to start or stop these ink reactions.
To paint the actual radial reaction, ToggleablePainter::paint_radial_reaction may
be used.
Sourcefn reaction(self: Handle<Self>, app: &App) -> &Ref<CurvedAnimation>
fn reaction(self: Handle<Self>, app: &App) -> &Ref<CurvedAnimation>
The visual value of the radial reaction animation.
Some controls have a radial ink reaction to user input. This animation controls the progress of these ink reactions.
To paint the actual radial reaction, ToggleablePainter::paint_radial_reaction may
be used.
Sourcefn reaction_hover_fade(self: Handle<Self>, app: &App) -> &Ref<CurvedAnimation>
fn reaction_hover_fade(self: Handle<Self>, app: &App) -> &Ref<CurvedAnimation>
Controls the radial reaction’s opacity animation for hover changes.
Some controls have a radial ink reaction to pointer hover. This animation controls these ink reaction fade-ins and fade-outs.
To paint the actual radial reaction, ToggleablePainter::paint_radial_reaction may
be used.
Sourcefn reaction_focus_fade(self: Handle<Self>, app: &App) -> &Ref<CurvedAnimation>
fn reaction_focus_fade(self: Handle<Self>, app: &App) -> &Ref<CurvedAnimation>
Controls the radial reaction’s opacity animation for focus changes.
Some controls have a radial ink reaction to focus. This animation controls these ink reaction fade-ins and fade-outs.
To paint the actual radial reaction, ToggleablePainter::paint_radial_reaction may
be used.
Sourcefn reaction_animation_duration(
self: Handle<Self>,
app: &App,
) -> Option<Duration>
fn reaction_animation_duration( self: Handle<Self>, app: &App, ) -> Option<Duration>
The amount of time a circular ink response should take to expand to its full size if a
radial reaction is drawn using ToggleablePainter::paint_radial_reaction.
Sourcefn is_interactive(self: Handle<Self>, app: &App) -> bool
fn is_interactive(self: Handle<Self>, app: &App) -> bool
Whether value of this control can be changed by user interaction.
The control is considered interactive if the on_changed callback
is non-null. If the callback is null, then the control is disabled, and
non-interactive. A disabled checkbox, for example, is displayed using a grey color and
its value cannot be changed.
Sourcefn init_state(self: Handle<Self>, app: &mut App)
fn init_state(self: Handle<Self>, app: &mut App)
The mixin’s part of State::init_state; the state calls it first, where Dart’s
super.initState() reaches the mixin.
Sourcefn animate_to_value(self: Handle<Self>, app: &mut App)
fn animate_to_value(self: Handle<Self>, app: &mut App)
Sourcefn dispose(self: Handle<Self>, app: &mut App)
fn dispose(self: Handle<Self>, app: &mut App)
The mixin’s part of State::dispose; the state calls it where Dart’s super.dispose()
reaches the mixin, then TickerProviderStateMixin::dispose.
Sourcefn down_position(self: Handle<Self>, app: &App) -> Option<Offset>
fn down_position(self: Handle<Self>, app: &App) -> Option<Offset>
The most recent Offset at which a pointer touched the Toggleable.
This is null if currently no pointer is touching the Toggleable or if
is_interactive is false.
Sourcefn states(self: Handle<Self>, app: &App) -> WidgetStates
fn states(self: Handle<Self>, app: &App) -> WidgetStates
Describes the current WidgetState of the Toggleable.
The returned set will include:
WidgetState::Disabled, ifis_interactiveis falseWidgetState::Hovered, if a pointer is hovering over the ToggleableWidgetState::Focused, if the Toggleable has input focusWidgetState::Selected, ifvalueis true or null
Sourcefn build_toggleable(
self: Handle<Self>,
app: &mut App,
focus_node: Option<FocusNodeRef>,
on_focus_change: Option<ValueChanged<bool>>,
autofocus: bool,
mouse_cursor: Option<WidgetStatePropertyRef<MouseCursorRef>>,
size: Size,
painter: impl CustomPainter,
) -> WidgetRef
fn build_toggleable( self: Handle<Self>, app: &mut App, focus_node: Option<FocusNodeRef>, on_focus_change: Option<ValueChanged<bool>>, autofocus: bool, mouse_cursor: Option<WidgetStatePropertyRef<MouseCursorRef>>, size: Size, painter: impl CustomPainter, ) -> WidgetRef
Typically wraps a painter that draws the actual visuals of the Toggleable with logic
to toggle it.
Use build_toggleable_with_child if one would
like to provide a widget instead of CustomPainter.
If drawing a radial ink reaction is desired (in Material Design for example), consider
providing a ToggleablePainter as a painter, which implements logic to draw a
radial ink reaction for this control. The painter is usually configured with the
reaction, position,
reaction_hover_fade, and
reaction_focus_fade animation provided by this mixin. It
is expected to draw the visuals of the Toggleable based on the current value of these
animations. The animations are triggered by this mixin to transition the Toggleable
from one state to another.
Material Toggleables must provide a mouse_cursor which resolves to a mouse cursor
based on the current WidgetState of the Toggleable. Cupertino Toggleables may not
provide a mouse_cursor. If no mouse_cursor is provided,
SystemMouseCursors::BASIC will be used as the mouse_cursor across all
WidgetStates.
This method must be called from the build method of the state that uses this mixin.
The returned widget must be returned from the build method - potentially after wrapping
it in other widgets.
Sourcefn build_toggleable_with_child(
self: Handle<Self>,
app: &mut App,
focus_node: Option<FocusNodeRef>,
on_focus_change: Option<ValueChanged<bool>>,
autofocus: bool,
mouse_cursor: Option<WidgetStatePropertyRef<MouseCursorRef>>,
child: WidgetRef,
) -> WidgetRef
fn build_toggleable_with_child( self: Handle<Self>, app: &mut App, focus_node: Option<FocusNodeRef>, on_focus_change: Option<ValueChanged<bool>>, autofocus: bool, mouse_cursor: Option<WidgetStatePropertyRef<MouseCursorRef>>, child: WidgetRef, ) -> WidgetRef
Typically wraps a child that draws the actual visuals of the Toggleable with logic to toggle it.
If drawing a radial ink reaction is desired (in Material Design for example), consider
providing a CustomPaint with a ToggleablePainter as its painter, which
implements logic to draw a radial ink reaction for this control. The painter is usually
configured with the reaction, position,
reaction_hover_fade, and
reaction_focus_fade animation provided by this mixin. It
is expected to draw the visuals of the Toggleable based on the current value of these
animations. The animations are triggered by this mixin to transition the Toggleable
from one state to another.
Material Toggleables must provide a mouse_cursor which resolves to a mouse cursor
based on the current WidgetState of the Toggleable. Cupertino Toggleables may not
provide a mouse_cursor. If no mouse_cursor is provided,
SystemMouseCursors::BASIC will be used as the mouse_cursor across all
WidgetStates.
This method must be called from the build method of the state that uses this mixin.
The returned widget must be returned from the build method - potentially after wrapping
it in other widgets.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".