pub struct LayoutBuilder {
pub key: Option<KeyRef>,
pub builder: LayoutWidgetBuilder,
/* private fields */
}Expand description
Builds a widget tree that can depend on the parent widget’s size.
Similar to the Builder widget except that the framework calls the
builder function at layout time and provides the parent widget’s
constraints. This is useful when the parent constrains the child’s size and doesn’t
depend on the child’s intrinsic size. The LayoutBuilder’s final size will match its
child’s size.
The builder function is called in the following situations:
- The first time the widget is laid out.
- When the parent widget passes different layout constraints.
- When the parent widget updates this widget.
- When the dependencies that the
builderfunction subscribes to change.
The builder function is not called during layout if the parent
passes the same constraints repeatedly.
If the child should be smaller than the parent, consider wrapping the child in an Align
widget. If the child might want to be bigger, consider wrapping it in a
SingleChildScrollView or OverflowBox.
See also:
SliverLayoutBuilder, the sliver counterpart of this widget.Builder, which calls abuildfunction at build time.StatefulBuilder, which passes itsbuildfunction asetStatecallback.CustomSingleChildLayout, which positions its child during layout.
Fields§
§key: Option<KeyRef>§builder: LayoutWidgetBuilderCalled at layout time to construct the widget tree.
The builder must not return null.
Implementations§
Source§impl LayoutBuilder
impl LayoutBuilder
Sourcepub fn new(
builder: impl Fn(&mut App, BuildContext, AnyBoxConstraints) -> WidgetRef + 'static,
) -> LayoutBuilder
pub fn new( builder: impl Fn(&mut App, BuildContext, AnyBoxConstraints) -> WidgetRef + 'static, ) -> LayoutBuilder
Creates a widget that defers its building until layout.
Sourcepub fn key(self, key: KeyRef) -> LayoutBuilder
pub fn key(self, key: KeyRef) -> LayoutBuilder
Dart LayoutBuilder(key:).
Sourcepub fn into_widget(self) -> WidgetRef
pub fn into_widget(self) -> WidgetRef
The tree node: a LayoutBuilder is its own tree node, which [IntoWidget] converts.
Sourcepub fn update_should_rebuild(&self, old_widget: &LayoutBuilder) -> bool
pub fn update_should_rebuild(&self, old_widget: &LayoutBuilder) -> bool
Whether builder needs to be called again even if the layout
constraints are the same.
When this widget’s configuration is updated, the builder callback
most likely needs to be called to build this widget’s child. However, subclasses may
provide ways in which the widget can be updated without needing to rebuild the child.
Such subclasses can use this method to tell the framework when the child widget
should be rebuilt.
When this method is called by the framework, the newly configured widget is asked if it requires a rebuild, and it is passed the old widget as a parameter.
Trait Implementations§
Source§impl Debug for LayoutBuilder
impl Debug for LayoutBuilder
Source§impl RenderObjectWidget for LayoutBuilder
impl RenderObjectWidget for LayoutBuilder
Source§type RenderObject = RenderLayoutBuilder
type RenderObject = RenderLayoutBuilder
covariant RenderObject parameter type.Source§fn create_render_object(
&self,
app: &mut App,
_context: BuildContext,
) -> AnyRenderObject
fn create_render_object( &self, app: &mut App, _context: BuildContext, ) -> AnyRenderObject
RenderObject class that this widget represents, using the
configuration described by this widget. Read moreSource§fn update_render_object(
&self,
_app: &mut App,
_context: BuildContext,
_render_object: RenderHandle<RenderLayoutBuilder>,
)
fn update_render_object( &self, _app: &mut App, _context: BuildContext, _render_object: RenderHandle<RenderLayoutBuilder>, )
create_render_object. Read moreSource§fn debug_fill_properties(
&self,
_app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )
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 to_string_short(&self) -> String
fn to_string_short(&self) -> String
toStringShort, for a widget that names itself apart from its type, as
SizedBox.expand does; see Widget::to_string_short.Source§fn debug_visit_onstage_children(
&self,
app: &App,
children: &[AnyElement],
visitor: &mut dyn FnMut(AnyElement),
)
fn debug_visit_onstage_children( &self, app: &App, children: &[AnyElement], visitor: &mut dyn FnMut(AnyElement), )
debugVisitOnstageChildren of the element this widget makes, for a widget whose
Dart element subclass overrides it only to hide children (_OffstageElement,
_IndexedStackElement): calls visitor for each of children, in order, that is
onstage. Waft’s generic single- and multi-child elements stand in for those subclasses
and ask their widget here; an element of a widget’s own overrides
Element::debug_visit_onstage_children instead.Source§fn did_unmount_render_object(
&self,
app: &mut App,
render_object: RenderHandle<Self::RenderObject>,
)
fn did_unmount_render_object( &self, app: &mut App, render_object: RenderHandle<Self::RenderObject>, )
RenderObject will be of the same type as returned by this object’s
create_render_object.Source§impl Widget for LayoutBuilder
impl Widget for LayoutBuilder
Source§fn key(&self) -> Option<&KeyRef>
fn key(&self) -> Option<&KeyRef>
Source§fn creation_location(&self) -> Option<&'static Location<'static>>
fn creation_location(&self) -> Option<&'static Location<'static>>
Source§fn record_creation_location(&mut self, location: CreationLocation)
fn record_creation_location(&mut self, location: CreationLocation)
creation_location to
answer: what into_widget calls on a widget that is its own tree node, which has no
wrapper to keep it in. Such a widget keeps it in a field
(created: Option<CreationLocation>); the default keeps nothing.Source§fn create_element(&self, app: &mut App, this: WidgetRef) -> AnyElement
fn create_element(&self, app: &mut App, this: WidgetRef) -> AnyElement
this is this widget’s shared
reference, which the element keeps.Source§fn widget_type(&self) -> TypeId
fn widget_type(&self) -> TypeId
runtimeType.Source§fn kind(&self) -> WidgetKind
fn kind(&self) -> WidgetKind
Element.updateChild’s superclass
check.Source§fn to_string_short(&self) -> String
fn to_string_short(&self) -> String
toStringShort: the type, then the key when there is one, as
Text-[<'title'>].Source§fn debug_fill_properties(
&self,
_app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )
debugFillProperties: the properties a dump shows for this widget, in Dart’s
order. Dart’s Widget base only sets the dense tree style, which
[to_diagnostics_node](Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
runtimeType prints in a message: the
type’s own name without its module path. Read moreSource§fn as_inherited_theme(&self) -> Option<&dyn InheritedTheme>
fn as_inherited_theme(&self) -> Option<&dyn InheritedTheme>
Source§fn as_render_object(&self) -> Option<&dyn AnyRenderObjectWidget>
fn as_render_object(&self) -> Option<&dyn AnyRenderObjectWidget>
RenderObjectWidget, when it is one of the three kinds the framework
makes elements for (leaf, single-child, multi-child): what those elements create and
update their render object through, so they are not copied per widget type.Source§fn as_single_child_render_object(
&self,
) -> Option<&dyn AnySingleChildRenderObjectWidget>
fn as_single_child_render_object( &self, ) -> Option<&dyn AnySingleChildRenderObjectWidget>
SingleChildRenderObjectWidget, when it is one.Source§fn as_multi_child_render_object(
&self,
) -> Option<&dyn AnyMultiChildRenderObjectWidget>
fn as_multi_child_render_object( &self, ) -> Option<&dyn AnyMultiChildRenderObjectWidget>
MultiChildRenderObjectWidget, when it is one.Source§fn as_parent_data(&self) -> Option<&dyn AnyParentDataWidget>
fn as_parent_data(&self) -> Option<&dyn AnyParentDataWidget>
ParentDataWidget, when it is one: what the one
ParentDataElement reads, so that element is not copied per widget type.Source§fn as_stateful(&self) -> Option<&dyn AnyStatefulWidget>
fn as_stateful(&self) -> Option<&dyn AnyStatefulWidget>
StatefulWidget, when it is one: what the one StatefulElement
creates its state through, so that element is not copied per widget type.Source§fn as_inherited(&self) -> Option<&dyn AnyInheritedWidget>
fn as_inherited(&self) -> Option<&dyn AnyInheritedWidget>
InheritedWidget, when it is one: what the one
InheritedElement reads, so that element is not copied per widget type.Source§fn as_stateless(&self) -> Option<&dyn StatelessWidget>
fn as_stateless(&self) -> Option<&dyn StatelessWidget>
StatelessWidget, when it is one: what the one
StatelessElement builds from, so that element is not copied per widget type.Source§fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>
fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>
widget is PreferredSizeWidget: this widget as a PreferredSizeWidget, when
it is one. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for LayoutBuilder
impl !Send for LayoutBuilder
impl !Sync for LayoutBuilder
impl !UnwindSafe for LayoutBuilder
impl Forget for LayoutBuilder
impl Freeze for LayoutBuilderwhere
*const RcInner<dyn Key> is !null: Freeze,
PhantomData<RcInner<dyn Key>>: Freeze,
*const RcInner<dyn Fn(&mut App, AnyElement, AnyBoxConstraints) -> Rc<dyn Widget>> is !null: Freeze,
PhantomData<RcInner<dyn Fn(&mut App, AnyElement, AnyBoxConstraints) -> Rc<dyn Widget>>>: Freeze,
&'static Location<'static>: Freeze,
impl Move for LayoutBuilder
impl Unpin for LayoutBuilder
impl UnsafeUnpin for LayoutBuilderwhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
*const RcInner<dyn Fn(&mut App, AnyElement, AnyBoxConstraints) -> Rc<dyn Widget>> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Fn(&mut App, AnyElement, AnyBoxConstraints) -> Rc<dyn Widget>>>: UnsafeUnpin,
&'static Location<'static>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<W> IntoWidget<TreeNodeKind> for Wwhere
W: Widget,
impl<W> IntoWidget<TreeNodeKind> for Wwhere
W: Widget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.