pub trait State: Sized + 'static {
type Widget: StatefulWidget<State = Self>;
// Required method
fn build(&self, cx: &StateContext<'_, '_, Self>) -> Box<dyn Widget>;
// Provided methods
fn init_state(&mut self, _cx: &StateContext<'_, '_, Self>) { ... }
fn did_update_widget(
&mut self,
_old: &Self::Widget,
_cx: &StateContext<'_, '_, Self>,
) { ... }
fn dispose(&mut self) { ... }
}Expand description
What a StatefulWidget keeps, and how it draws itself from it.
Required Associated Types§
Sourcetype Widget: StatefulWidget<State = Self>
type Widget: StatefulWidget<State = Self>
The widget this is the state of.
Required Methods§
Sourcefn build(&self, cx: &StateContext<'_, '_, Self>) -> Box<dyn Widget>
fn build(&self, cx: &StateContext<'_, '_, Self>) -> Box<dyn Widget>
The widget this state stands for. Called whenever the tree is rebuilt.
It only reads the state. What a handler changes goes through
StateContext::callback or StateContext::handle; changing the state from
inside build itself panics, because a build that changes what it builds from
never settles.
Provided Methods§
Sourcefn init_state(&mut self, _cx: &StateContext<'_, '_, Self>)
fn init_state(&mut self, _cx: &StateContext<'_, '_, Self>)
Called once, right after the state is made. Start what has to run for as long as
the widget is there — a listener, a timer — here, and stop it in
State::dispose.
Sourcefn did_update_widget(
&mut self,
_old: &Self::Widget,
_cx: &StateContext<'_, '_, Self>,
)
fn did_update_widget( &mut self, _old: &Self::Widget, _cx: &StateContext<'_, '_, Self>, )
Called when the tree is rebuilt and the widget above changed, or was made again.
old is the configuration it replaces; the new one is StateContext::widget.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".