performLayout method

  1. @override
void performLayout()
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 change its layout information without informing this render object.

Implementation

@override
void performLayout() {
  assert(() {
    if (!scrollable || !constraints.hasBoundedHeight) return true;
    throw FlutterError.fromParts(<DiagnosticsNode>[
      ErrorSummary('RenderEditableContainerBox must have '
          'unlimited space along its main axis when it is scrollable.'),
      ErrorDescription('RenderEditableContainerBox does not clip or'
          ' resize its children, so it must be '
          'placed in a parent that does not constrain the main '
          'axis.'),
      ErrorHint(
          'You probably want to put the RenderEditableContainerBox inside a '
          'RenderViewport with a matching main axis or disable the '
          'scrollable property.')
    ]);
  }());
  assert(() {
    if (constraints.hasBoundedWidth) return true;
    throw FlutterError.fromParts(<DiagnosticsNode>[
      ErrorSummary('RenderEditableContainerBox must have a bounded'
          ' constraint for its cross axis.'),
      ErrorDescription('RenderEditableContainerBox forces its children to '
          "expand to fit the RenderEditableContainerBox's container, "
          'so it must be placed in a parent that constrains the cross '
          'axis to a finite dimension.'),
    ]);
  }());

  resolvePadding();
  assert(resolvedPadding != null);

  var mainAxisExtent = resolvedPadding!.top;
  var child = firstChild;
  final innerConstraints = BoxConstraints.tightFor(
          width: math.min(
              _maxContentWidth ?? double.infinity, constraints.maxWidth))
      .deflate(resolvedPadding!);
  final leftOffset = _maxContentWidth == null
      ? 0.0
      : math.max((constraints.maxWidth - _maxContentWidth!) / 2, 0);
  while (child != null) {
    child.layout(innerConstraints, parentUsesSize: true);
    final childParentData = child.parentData as EditableContainerParentData
      ..offset = Offset(resolvedPadding!.left + leftOffset, mainAxisExtent);
    mainAxisExtent += child.size.height;
    assert(child.parentData == childParentData);
    child = childParentData.nextSibling;
  }
  mainAxisExtent += resolvedPadding!.bottom;
  size = constraints.constrain(Size(constraints.maxWidth, mainAxisExtent));

  assert(size.isFinite);
}