- override
Do the work of computing the layout for this render object.
Do not call this function directly: call layout
instead. This function
is called by layout
when there is actually work to be done by this
render object during layout. The layout constraints provided by your
parent are available via the constraints
getter.
If sizedByParent
is true, then this function should not actually change
the dimensions of this render object. Instead, that work should be done by
performResize
. If sizedByParent
is false, then this function should
both change the dimensions of this render object and instruct its children
to layout.
In implementing this function, you must call layout
on each of your
children, passing true for parentUsesSize if your layout information is
dependent on your child's layout information. Passing true for
parentUsesSize ensures that this render object will undergo layout if the
child undergoes layout. Otherwise, the child can changes its layout
information without informing this render object.
Source
@override void performLayout() { assert(() { switch (mainAxis) { case Axis.horizontal: if (!constraints.hasBoundedWidth) return true; break; case Axis.vertical: if (!constraints.hasBoundedHeight) return true; break; } throw new FlutterError( 'RenderBlock must have unlimited space along its main axis.\n' 'RenderBlock does not clip or resize its children, so it must be ' 'placed in a parent that does not constrain the block\'s main ' 'axis. You probably want to put the RenderBlock inside a ' 'RenderViewport with a matching main axis.' ); }); assert(() { switch (mainAxis) { case Axis.horizontal: if (constraints.hasBoundedHeight) return true; break; case Axis.vertical: if (constraints.hasBoundedWidth) return true; break; } // TODO(ianh): Detect if we're actually nested blocks and say something // more specific to the exact situation in that case, and don't mention // nesting blocks in the negative case. throw new FlutterError( 'RenderBlock must have a bounded constraint for its cross axis.\n' 'RenderBlock forces its children to expand to fit the block\'s container, ' 'so it must be placed in a parent that does constrain the block\'s cross ' 'axis to a finite dimension. If you are attempting to nest a block with ' 'one direction inside a block of another direction, you will want to ' 'wrap the inner one inside a box that fixes the dimension in that direction, ' 'for example, a RenderIntrinsicWidth or RenderIntrinsicHeight object. ' 'This is relatively expensive, however.' // (that's why we don't do it automatically) ); }); BoxConstraints innerConstraints = _getInnerConstraints(constraints); double position = 0.0; RenderBox child = firstChild; while (child != null) { child.layout(innerConstraints, parentUsesSize: true); final BlockParentData childParentData = child.parentData; switch (mainAxis) { case Axis.horizontal: childParentData.offset = new Offset(position, 0.0); position += child.size.width; break; case Axis.vertical: childParentData.offset = new Offset(0.0, position); position += child.size.height; break; } assert(child.parentData == childParentData); child = childParentData.nextSibling; } switch (mainAxis) { case Axis.horizontal: size = constraints.constrain(new Size(_mainAxisExtent, constraints.maxHeight)); break; case Axis.vertical: size = constraints.constrain(new Size(constraints.maxWidth, _mainAxisExtent)); break; } assert(!size.isInfinite); }