LayoutBoxWidget class
A flexible layout container that supports scrolling and custom layout algorithms.
LayoutBox is a fundamental building block for creating custom layouts in Flutter. It provides scrolling capabilities, overflow handling, and integrates with custom layout algorithms through the Layout interface.
Basic Usage
LayoutBoxWidget(
layout: FlexLayout(
direction: FlexDirection.row,
alignItems: BoxAlignmentGeometry.center,
),
children: [
Text('Item 1'),
Text('Item 2'),
],
)
Scrolling
LayoutBox automatically provides scrolling when content overflows:
- horizontalOverflow and verticalOverflow control scroll behavior
- horizontalController and verticalController allow programmatic scrolling
- diagonalDragBehavior controls how diagonal gestures are interpreted
Layout Algorithms
The layout property defines how children are positioned and sized. Built-in layouts include FlexLayout for flexbox behavior, but custom layouts can be implemented by extending the Layout class.
Text Direction
The textDirection property affects directional alignments and scrolling. If null, it uses the ambient Directionality from the widget tree.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- LayoutBoxWidget
- Available extensions
Constructors
-
LayoutBoxWidget({Key? key, TextDirection? textDirection, bool reversePaint = false, LayoutOverflow horizontalOverflow = LayoutOverflow.visible, LayoutOverflow verticalOverflow = LayoutOverflow.visible, ScrollController? horizontalController, ScrollController? verticalController, DiagonalDragBehavior diagonalDragBehavior = DiagonalDragBehavior.free, Axis mainScrollDirection = Axis.vertical, TextBaseline? textBaseline, BorderRadiusGeometry? borderRadius, Clip clipBehavior = Clip.hardEdge, bool reverseHorizontalScroll = false, bool reverseVerticalScroll = false, required Layout layout, required List<
Widget> children}) -
Creates a layout container with the specified properties.
const
Properties
- asAbsoluteItem → Widget
-
Available on Widget, provided by the WidgetExtension extension
Explicitly wraps this widget as an AbsoluteItem.no setter - asFlexItem → Widget
-
Available on Widget, provided by the WidgetExtension extension
Explicitly wraps this widget as a FlexItem.no setter - borderRadius → BorderRadiusGeometry?
-
The border radius applied to the container's background and clipping.
final
-
children
→ List<
Widget> -
The list of child widgets to layout.
final
- clipBehavior → Clip
-
How to clip content that extends beyond the container bounds.
final
- diagonalDragBehavior → DiagonalDragBehavior
-
Controls how diagonal drag gestures are interpreted.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- horizontalController → ScrollController?
-
Controller for horizontal scrolling.
final
- horizontalOverflow → LayoutOverflow
-
How to handle content that exceeds horizontal bounds.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- layout → Layout
-
The layout algorithm to use for positioning and sizing children.
final
- mainScrollDirection → Axis
-
The primary scrolling axis for layout optimizations.
final
- reverseHorizontalScroll → bool
-
Whether to reverse the horizontal scroll direction.
final
- reversePaint → bool
-
Whether to reverse the paint order of children.
final
- reverseVerticalScroll → bool
-
Whether to reverse the vertical scroll direction.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- textBaseline → TextBaseline?
-
The text baseline to use for text alignment.
final
- textDirection → TextDirection?
-
The text direction for resolving directional layout properties.
final
- verticalController → ScrollController?
-
Controller for vertical scrolling.
final
- verticalOverflow → LayoutOverflow
-
How to handle content that exceeds vertical bounds.
final
Methods
-
aspectRatio(
double aspectRatio, [Key? key]) → Widget -
Available on Widget, provided by the WidgetExtension extension
Sets the aspect ratio constraint for this widget. -
bottom(
PositionUnit bottom, [Key? key]) → Widget -
Available on Widget, provided by the WidgetExtension extension
Sets the distance from the bottom edge of the parent container. -
constrained(
{SizeUnit? minWidth, SizeUnit? maxWidth, SizeUnit? minHeight, SizeUnit? maxHeight, Key? key}) → Widget -
Available on Widget, provided by the WidgetExtension extension
Sets comprehensive size constraints including both minimum and maximum bounds. -
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< LayoutBoxWidget> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
override
-
flexGrow(
double flexGrow, [Key? key]) → Widget -
Available on Widget, provided by the WidgetExtension extension
Sets the flex grow factor for this widget within a flex container. -
flexShrink(
double flexShrink, [Key? key]) → Widget -
Available on Widget, provided by the WidgetExtension extension
Sets the flex shrink factor for this widget within a flex container. -
height(
SizeUnit height, [Key? key]) → Widget -
Available on Widget, provided by the WidgetExtension extension
Sets the height of this widget using a SizeUnit. -
id(
Object valueKey) → Widget -
Available on Widget, provided by the WidgetExtension extension
Assigns a ValueKey to this widget using the provided value. -
key(
Key key) → Widget -
Available on Widget, provided by the WidgetExtension extension
Assigns a Key to this widget. -
left(
PositionUnit left, [Key? key]) → Widget -
Available on Widget, provided by the WidgetExtension extension
Sets the distance from the left edge of the parent container. -
maxHeight(
SizeUnit maxHeight, [Key? key]) → Widget -
Available on Widget, provided by the WidgetExtension extension
Sets the maximum height constraint for this widget using a SizeUnit. -
maxSized(
{SizeUnit? maxWidth, SizeUnit? maxHeight, Key? key}) → Widget -
Available on Widget, provided by the WidgetExtension extension
Sets maximum width and height constraints simultaneously. -
maxWidth(
SizeUnit maxWidth, [Key? key]) → Widget -
Available on Widget, provided by the WidgetExtension extension
Sets the maximum width constraint for this widget using a SizeUnit. -
minHeight(
SizeUnit minHeight, [Key? key]) → Widget -
Available on Widget, provided by the WidgetExtension extension
Sets the minimum height constraint for this widget using a SizeUnit. -
minSized(
{SizeUnit? minWidth, SizeUnit? minHeight, Key? key}) → Widget -
Available on Widget, provided by the WidgetExtension extension
Sets minimum width and height constraints simultaneously. -
minWidth(
SizeUnit minWidth, [Key? key]) → Widget -
Available on Widget, provided by the WidgetExtension extension
Sets the minimum width constraint for this widget using a SizeUnit. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
paintOrder(
int paintOrder, [Key? key]) → Widget -
Available on Widget, provided by the WidgetExtension extension
Sets the paint order for this widget within its parent container. -
position(
PositionType position, [Key? key]) → Widget -
Available on Widget, provided by the WidgetExtension extension
Sets the position type for this widget to control positioning context. -
positioned(
{PositionUnit? top, PositionUnit? left, PositionUnit? bottom, PositionUnit? right, Key? key}) → Widget -
Available on Widget, provided by the WidgetExtension extension
Positions the widget using multiple edge offsets simultaneously. -
right(
PositionUnit right, [Key? key]) → Widget -
Available on Widget, provided by the WidgetExtension extension
Sets the distance from the right edge of the parent container. -
selfAligned(
BoxAlignmentGeometry alignSelf, [Key? key]) → Widget -
Available on Widget, provided by the WidgetExtension extension
Sets the alignment of this widget within its parent flex container. -
sized(
{SizeUnit? width, SizeUnit? height, Key? key}) → Widget -
Available on Widget, provided by the WidgetExtension extension
Sets both width and height dimensions simultaneously. -
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
top(
PositionUnit top, [Key? key]) → Widget -
Available on Widget, provided by the WidgetExtension extension
Sets the distance from the top edge of the parent container. -
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
-
width(
SizeUnit width, [Key? key]) → Widget -
Available on Widget, provided by the WidgetExtension extension
Sets the width of this widget using a SizeUnit.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited