StreamFlex class
A widget that displays its children in a one-dimensional array, supporting negative spacing and collapsed (nullable) children.
StreamFlex allows you to control the axis along which the children are placed (horizontal or vertical). The spacing parameter can be positive (gap between children), zero (flush), or negative (children overlap).
If you know the main axis in advance, consider using StreamRow (horizontal) or StreamColumn (vertical) instead, since that will be less verbose.
Collapsed children
Children built with NullableStatelessWidget, NullableStatefulWidget,
or NullableBuilder can return null from their nullableBuild method.
When they do, they collapse to zero size and no spacing is allocated
for them.
In a regular Row or Column, a zero-size child still occupies a spacing slot. StreamFlex (and its subclasses) detect collapsed children and exclude them from spacing calculations entirely.
{@tool snippet}
A column with 8px spacing where the subtitle conditionally collapses.
When showSubtitle is false, only one 8px gap remains between "Title"
and "Body" — the collapsed child does not add an extra spacing slot:
StreamColumn(
spacing: 8,
children: [
Text('Title'),
NullableBuilder(builder: (context) {
if (!showSubtitle) return null;
return const Text('Subtitle');
}),
Text('Body'),
],
)
{@end-tool}
{@tool snippet}
Overlapping avatars with -8px spacing:
StreamRow(
spacing: -8,
children: [
CircleAvatar(child: Text('A')),
CircleAvatar(child: Text('B')),
CircleAvatar(child: Text('C')),
],
)
{@end-tool}
Layout algorithm
- Layout inflexible children with unbounded main-axis constraints.
- Distribute remaining main-axis space to flexible children.
- Layout flexible children with allocated space.
- Cross-axis extent = maximum child cross extent.
- Main-axis extent determined by mainAxisSize and constraints.
- Position children according to mainAxisAlignment and crossAxisAlignment, applying spacing between each pair.
Collapsed children are excluded from all steps above.
With negative spacing, the total main-axis extent shrinks and children are positioned closer together, producing overlap. Later children in the list paint on top of earlier ones (natural z-order).
See also:
- StreamRow, for a horizontal variant.
- StreamColumn, for a vertical variant.
- NullableBuilder, for inline nullable children.
- NullableStatelessWidget, for reusable nullable widgets.
- NullableStatefulWidget, for stateful nullable widgets.
- Inheritance
- Implementers
Constructors
-
StreamFlex({Key? key, required Axis direction, MainAxisAlignment mainAxisAlignment = MainAxisAlignment.start, MainAxisSize mainAxisSize = MainAxisSize.min, CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.center, TextDirection? textDirection, VerticalDirection verticalDirection = VerticalDirection.down, TextBaseline? textBaseline, Clip clipBehavior = Clip.none, double spacing = 0.0, List<
Widget> children = const <Widget>[]}) -
Creates a flex layout that supports negative spacing.
const
Properties
-
children
→ List<
Widget> -
The widgets below this widget in the tree.
finalinherited
- clipBehavior → Clip
-
How to clip children that extend beyond the widget's bounds.
final
- crossAxisAlignment → CrossAxisAlignment
-
How the children should be placed along the cross axis.
final
- direction → Axis
-
The direction to use as the main axis.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- mainAxisAlignment → MainAxisAlignment
-
How the children should be placed along the main axis.
final
- mainAxisSize → MainAxisSize
-
How much space should be occupied in the main axis.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- spacing → double
-
The amount of space between children along the main axis.
final
- textBaseline → TextBaseline?
-
If aligning items according to their baseline, which baseline to use.
final
- textDirection → TextDirection?
-
Determines the order to lay children out horizontally and how to interpret
startandendin the horizontal direction.final - verticalDirection → VerticalDirection
-
Determines the order to lay children out vertically and how to interpret
startandendin the vertical direction.final
Methods
-
createElement(
) → MultiChildRenderObjectElement -
RenderObjectWidgets always inflate to a RenderObjectElement subclass.
inherited
-
createRenderObject(
BuildContext context) → RenderFlex -
Creates an instance of the RenderObject class that this
RenderObjectWidget represents, using the configuration described by this
RenderObjectWidget.
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.
inherited
-
didUnmountRenderObject(
covariant RenderObject renderObject) → void -
This method is called when a RenderObject that was previously
associated with this widget is removed from the render tree.
The provided RenderObject will be of the same type as the one created by
this widget's createRenderObject method.
inherited
-
getEffectiveTextDirection(
BuildContext context) → TextDirection? - The resolved text direction for layout.
-
noSuchMethod(
Invocation invocation) → 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 debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
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
-
updateRenderObject(
BuildContext context, covariant RenderFlex renderObject) → void -
Copies the configuration described by this RenderObjectWidget to the
given RenderObject, which will be of the same type as returned by this
object's createRenderObject.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited