Movatterモバイル変換


[0]ホーム

URL:


menu
  1. Flutter
  2. widgets.dart
  3. LayoutBuilder class
LayoutBuilder
description

LayoutBuilder class

Builds a widget tree that can depend on the parent widget's size.

Similar to theBuilder widget except that the framework calls thebuilderfunction at layout time and provides the parent widget's constraints. Thisis useful when the parent constrains the child's size and doesn't depend onthe child's intrinsic size. TheLayoutBuilder's final size will match itschild's size.

Thebuilder 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 andupdateShouldRebuild returnstrue.
  • When the dependencies that thebuilder function subscribes to change.

Thebuilder function isnot called during layout if the parent passesthe same constraints repeatedly.

In the event that an ancestor skips the layout of this subtree so theconstraints become outdated, thebuilder rebuilds with the last knownconstraints.

If the child should be smaller than the parent, consider wrapping the childin anAlign widget. If the child might want to be bigger, considerwrapping it in aSingleChildScrollView orOverflowBox.

This example uses aLayoutBuilder to build a different widget depending on the available width. Resize theDartPad window to seeLayoutBuilder in action!
link

To create a local project with this code sample, run:
flutter create --sample=widgets.LayoutBuilder.1 mysample

See also:

Inheritance

Constructors

LayoutBuilder({Key?key,requiredWidgetbuilder(BuildContextcontext,BoxConstraintsconstraints)})
Creates a widget that defers its building until layout.
const

Properties

builderWidget Function(BuildContextcontext,BoxConstraintsconstraints)
Called at layout time to construct the widget tree.
finalinherited
hashCodeint
The hash code for this object.
no setterinherited
keyKey?
Controls how one widget replaces another widget in the tree.
finalinherited
runtimeTypeType
A representation of the runtime type of the object.
no setterinherited

Methods

createElement()RenderObjectElement
RenderObjectWidgets always inflate to aRenderObjectElement subclass.
inherited
createRenderObject(BuildContextcontext)RenderAbstractLayoutBuilderMixin<BoxConstraints,RenderBox>
Creates an instance of theRenderObject class that thisRenderObjectWidget represents, using the configuration described by thisRenderObjectWidget.
override
debugDescribeChildren()List<DiagnosticsNode>
Returns a list ofDiagnosticsNode objects describing this node'schildren.
inherited
debugFillProperties(DiagnosticPropertiesBuilderproperties)→ void
Add additional properties associated with the node.
inherited
didUnmountRenderObject(covariantRenderObjectrenderObject)→ void
This method is called when a RenderObject that was previouslyassociated with this widget is removed from the render tree.The providedRenderObject will be of the same type as the one created bythis widget'screateRenderObject method.
inherited
noSuchMethod(Invocationinvocation)→ dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String?name,DiagnosticsTreeStyle?style})DiagnosticsNode
Returns a debug representation of the object that is used by debuggingtools and byDiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevelminLevel =DiagnosticLevel.info})String
A string representation of this object.
inherited
toStringDeep({StringprefixLineOne ='',String?prefixOtherLines,DiagnosticLevelminLevel =DiagnosticLevel.debug,intwrapWidth =65})String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({Stringjoiner =', ',DiagnosticLevelminLevel =DiagnosticLevel.debug})String
Returns a one-line detailed description of the object.
inherited
toStringShort()String
A short, textual description of this widget.
inherited
updateRenderObject(BuildContextcontext,covariantRenderObjectrenderObject)→ void
Copies the configuration described by thisRenderObjectWidget to thegivenRenderObject, which will be of the same type as returned by thisobject'screateRenderObject.
inherited
updateShouldRebuild(covariantAbstractLayoutBuilder<BoxConstraints>oldWidget)bool
Whetherbuilder needs to be called again even if the layout constraintsare the same.
inherited

Operators

operator ==(Objectother)bool
The equality operator.
inherited
  1. Flutter
  2. widgets
  3. LayoutBuilder class
widgets library

[8]ページ先頭

©2009-2026 Movatter.jp