performResize method

  1. @override
void performResize ()
override

Updates the render objects size using only the constraints.

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.

Subclasses that set sizedByParent to true should override this method to compute their size.

This function is called only if sizedByParent is true.

Implementation

@override
void performResize() {
  assert(() {
    if (!constraints.hasBoundedHeight || !constraints.hasBoundedWidth) {
      switch (axis) {
        case Axis.vertical:
          if (!constraints.hasBoundedHeight) {
            throw FlutterError(
              'Vertical viewport was given unbounded height.\n'
              'Viewports expand in the scrolling direction to fill their container.'
              'In this case, a vertical viewport was given an unlimited amount of '
              'vertical space in which to expand. This situation typically happens '
              'when a scrollable widget is nested inside another scrollable widget.\n'
              'If this widget is always nested in a scrollable widget there '
              'is no need to use a viewport because there will always be enough '
              'vertical space for the children. In this case, consider using a '
              'Column instead. Otherwise, consider using the "shrinkWrap" property '
              '(or a ShrinkWrappingViewport) to size the height of the viewport '
              'to the sum of the heights of its children.'
            );
          }
          if (!constraints.hasBoundedWidth) {
            throw FlutterError(
              'Vertical viewport was given unbounded width.\n'
              'Viewports expand in the cross axis to fill their container and '
              'constrain their children to match their extent in the cross axis. '
              'In this case, a vertical viewport was given an unlimited amount of '
              'horizontal space in which to expand.'
            );
          }
          break;
        case Axis.horizontal:
          if (!constraints.hasBoundedWidth) {
            throw FlutterError(
              'Horizontal viewport was given unbounded width.\n'
              'Viewports expand in the scrolling direction to fill their container.'
              'In this case, a horizontal viewport was given an unlimited amount of '
              'horizontal space in which to expand. This situation typically happens '
              'when a scrollable widget is nested inside another scrollable widget.\n'
              'If this widget is always nested in a scrollable widget there '
              'is no need to use a viewport because there will always be enough '
              'horizontal space for the children. In this case, consider using a '
              'Row instead. Otherwise, consider using the "shrinkWrap" property '
              '(or a ShrinkWrappingViewport) to size the width of the viewport '
              'to the sum of the widths of its children.'
            );
          }
          if (!constraints.hasBoundedHeight) {
            throw FlutterError(
              'Horizontal viewport was given unbounded height.\n'
              'Viewports expand in the cross axis to fill their container and '
              'constrain their children to match their extent in the cross axis. '
              'In this case, a horizontal viewport was given an unlimited amount of '
              'vertical space in which to expand.'
            );
          }
          break;
      }
    }
    return true;
  }());
  size = constraints.biggest;
  // We ignore the return value of applyViewportDimension below because we are
  // going to go through performLayout next regardless.
  switch (axis) {
    case Axis.vertical:
      offset.applyViewportDimension(size.height);
      break;
    case Axis.horizontal:
      offset.applyViewportDimension(size.width);
      break;
  }
}