pub trait StatelessWidget: Debug + 'static {
// Required method
fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef;
// Provided methods
fn key(&self) -> Option<&KeyRef> { ... }
fn debug_fill_properties(
&self,
_app: &App,
properties: &mut DiagnosticPropertiesBuilder,
) { ... }
fn debug_check_constructor(&self) { ... }
fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget> { ... }
}Expand description
A widget that does not require mutable state.
A stateless widget is a widget that describes part of the user interface by building a
constellation of other widgets that describe the user interface more concretely. The
building process continues recursively until the description of the user interface is
fully concrete (e.g., consists entirely of RenderObjectWidgets, which describe concrete
RenderObjects).
Required Methods§
Sourcefn build(&self, app: &mut App, context: BuildContext) -> WidgetRef
fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef
Describes the part of the user interface represented by this widget.
The framework calls this method when this widget is inserted into the tree in a given
BuildContext and when the dependencies of this widget change (e.g., an
InheritedWidget referenced by this widget changes). This method can potentially be
called in every frame and should not have any side effects beyond building a widget.
Provided Methods§
Sourcefn key(&self) -> Option<&KeyRef>
fn key(&self) -> Option<&KeyRef>
See Widget::key.
Sourcefn debug_fill_properties(
&self,
_app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
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.
Sourcefn debug_check_constructor(&self)
fn debug_check_constructor(&self)
Dart’s constructor asserts that relate two or more arguments.
A fluent chain of setters has seen every argument only once it ends, so the framework
calls this in a debug build when the widget is turned into a WidgetRef
(into_widget), and a bad combination panics where the widget is handed to the tree.
An assert on one argument stays in that argument’s setter.
Sourcefn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>
fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>
Dart’s this is PreferredSizeWidget: a widget that implements PreferredSizeWidget
answers with itself, which is what a parent asking an erased child for its preferred
size reads.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".