layout method

SliverGeometry layout(
  1. SliverConstraints constraints, {
  2. bool useSize = true,
})

Lays out the child with the specified constraints and returns its geometry.

If useSize is true or absent, this boxy will re-layout when the child changes size.

This method should only be called inside BoxyDelegate.layout.

Implementation

SliverGeometry layout(SliverConstraints constraints, {bool useSize = true}) {
  if (_parent.isDryLayout) {
    _parent.debugThrowLayout(
      CannotLayoutSliverError(
        delegate: _parent.delegate,
        render: _parent,
        child: this,
      ),
    );
  }

  assert(() {
    if (_parent.debugPhase != BoxyDelegatePhase.layout) {
      throw FlutterError(
          'The ${_parent.delegate} boxy delegate tried to lay out a child outside of the layout method.\n');
    }

    if (!_parent.debugChildrenNeedingLayout.remove(id)) {
      throw FlutterError(
          'The ${_parent.delegate} boxy delegate tried to lay out the child with id "$id" more than once.\n'
          'Each child must be laid out exactly once.');
    }

    try {
      assert(constraints.debugAssertIsValid(isAppliedConstraint: true));
    } on AssertionError catch (exception) {
      throw FlutterError(
          'The ${_parent.delegate} boxy delegate provided invalid box constraints for the child with id "$id".\n'
          '$exception\n'
          'The minimum width and height must be greater than or equal to zero.\n'
          'The maximum width must be greater than or equal to the minimum width.\n'
          'The maximum height must be greater than or equal to the minimum height.');
    }

    return true;
  }());

  render.layout(constraints, parentUsesSize: useSize);

  return render.geometry!;
}