Skip to main content

StatelessWidget

Trait StatelessWidget 

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

Source

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§

Source

fn key(&self) -> Option<&KeyRef>

Source

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.

Source

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.

Source

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

Implementors§

Source§

impl StatelessWidget for Builder

Source§

impl StatelessWidget for CallbackShortcuts

Source§

impl StatelessWidget for CameraPreview

Source§

impl StatelessWidget for CheckedModeBanner

Source§

impl StatelessWidget for Container

Source§

impl StatelessWidget for CustomScrollView

Source§

impl StatelessWidget for DefaultTextEditingShortcuts

Source§

impl StatelessWidget for DeviceOrientationBuilder

Source§

impl StatelessWidget for ExcludeFocus

Source§

impl StatelessWidget for ExcludeFocusTraversal

Source§

impl StatelessWidget for GestureDetector

Source§

impl StatelessWidget for GridView

Source§

impl StatelessWidget for HeroMode

Source§

impl StatelessWidget for Icon

Source§

impl StatelessWidget for IndexedStack

Source§

impl StatelessWidget for KeyedSubtree

Source§

impl StatelessWidget for ListView

Source§

impl StatelessWidget for ModalBarrier

Source§

impl StatelessWidget for NavigationToolbar

Source§

impl StatelessWidget for OrientationBuilder

Source§

impl StatelessWidget for PageStorage

Source§

impl StatelessWidget for Placeholder

Source§

impl StatelessWidget for PlatformSelectableRegionContextMenu

Source§

impl StatelessWidget for PlayerView

Source§

impl StatelessWidget for PositionedDirectional

Source§

impl StatelessWidget for PreferredSize

Source§

impl StatelessWidget for RawMagnifier

Source§

impl StatelessWidget for RawView

Source§

impl StatelessWidget for ReorderableDelayedDragStartListener

Source§

impl StatelessWidget for ReorderableDragStartListener

Source§

impl StatelessWidget for SafeArea

Source§

impl StatelessWidget for SingleChildScrollView

Source§

impl StatelessWidget for SliverFillRemaining

Source§

impl StatelessWidget for SliverFillViewport

Source§

impl StatelessWidget for SliverPersistentHeader

Source§

impl StatelessWidget for SliverSafeArea

Source§

impl StatelessWidget for Spacer

Source§

impl StatelessWidget for StretchEffect

Source§

impl StatelessWidget for SubtitleView

Source§

impl StatelessWidget for TableCell

Source§

impl StatelessWidget for Text

Source§

impl StatelessWidget for UnconstrainedBox

Source§

impl StatelessWidget for ViewAnchor

Source§

impl StatelessWidget for Visibility