pub struct WidgetStatesController { /* private fields */ }Expand description
Manages a set of WidgetStates and notifies listeners of changes.
Used by widgets that expose their internal state for the sake of
extensions that add support for additional states. See
TextButton for an example.
The controller’s value is its current set of states. Listeners
are notified whenever the value changes. The value should only be
changed with update; it should not be modified directly.
The controller’s value represents the set of states that a
widget’s visual properties, typically WidgetStateProperty
values, are resolved against. It is not the intrinsic state of
the widget. The widget is responsible for ensuring that the
controller’s value tracks its intrinsic state. For example one
cannot request the keyboard focus for a widget by adding
WidgetState::Focused to its controller. When the widget gains the
or loses the focus it will update its controller’s value and
notify listeners of the change.
When calling set_state in a WidgetStatesController listener, use the
SchedulerBinding::add_post_frame_callback to delay the call to set_state after
the frame has been rendered. It’s generally prudent to use the
SchedulerBinding::add_post_frame_callback because some of the widgets that
depend on WidgetStatesController may call update in their build method.
In such cases, listener’s that call set_state - during the build phase - will cause
an error.
Dart’s ValueNotifier<Set<WidgetState>> superclass is the change_notifier and value
fields here, with its value / set_value / dispose; the handle is a
Listenable.
See also:
MaterialStatesController, the Material specific version ofWidgetStatesController.
Implementations§
Source§impl WidgetStatesController
impl WidgetStatesController
Sourcepub fn new(
app: &mut App,
value: Option<WidgetStates>,
) -> Ref<WidgetStatesController>
pub fn new( app: &mut App, value: Option<WidgetStates>, ) -> Ref<WidgetStatesController>
Creates a WidgetStatesController.
Sourcepub fn value(&self) -> &WidgetStates
pub fn value(&self) -> &WidgetStates
The current set of states.
Sourcepub fn set_value(self: Handle<Self>, app: &mut App, new_value: WidgetStates)
pub fn set_value(self: Handle<Self>, app: &mut App, new_value: WidgetStates)
Replaces the current set of states, notifying listeners when it differs
(ValueNotifier’s setter). Prefer update.
Sourcepub fn dispose(self: Handle<Self>, app: &mut App)
pub fn dispose(self: Handle<Self>, app: &mut App)
Discards any resources used by the object; see ChangeNotifierData::dispose.
Trait Implementations§
Source§impl ChangeNotifier for WidgetStatesController
impl ChangeNotifier for WidgetStatesController
fn change_notifier_data(&self) -> &ChangeNotifierData
fn change_notifier_data_mut(&mut self) -> &mut ChangeNotifierData
Source§fn will_add_listener(self: Handle<Self>, app: &mut App)
fn will_add_listener(self: Handle<Self>, app: &mut App)
addListener that
work before super.addListener go here.Source§fn did_remove_listener(self: Handle<Self>, app: &mut App)
fn did_remove_listener(self: Handle<Self>, app: &mut App)
removeListener that
work after super.removeListener go here.