Skip to main content

ToggleableStateMixin

Trait ToggleableStateMixin 

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

Source

fn toggleable_data(self: Handle<Self>, app: &App) -> &ToggleableStateMixinData

Mixin field access.

Source

fn toggleable_data_mut( self: Handle<Self>, app: &mut App, ) -> &mut ToggleableStateMixinData

Source

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.

Source

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.

Source

fn tristate(self: Handle<Self>, app: &App) -> bool

If true, value can be true, false, or null, otherwise value must be true or false.

When tristate is true and value is null, then the control is considered to be in its third or “indeterminate” state.

Provided Methods§

Source

fn as_toggleable_state(self: Handle<Self>) -> AnyToggleableState

This state as the erased AnyToggleableState — what to pass where a Dart API takes a ToggleableStateMixin.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn animate_to_value(self: Handle<Self>, app: &mut App)

Runs the position animation to transition the Toggleable’s appearance to match value.

This method must be called whenever value changes to ensure that the visual representation of the Toggleable matches the current value.

Source

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.

Source

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.

Source

fn states(self: Handle<Self>, app: &App) -> WidgetStates

Describes the current WidgetState of the Toggleable.

The returned set will include:

Source

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.

Source

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".

Implementors§