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() {
  _resolve();
  assert(_resolvedPadding != null);
  final double beforePadding = this.beforePadding;
  final double afterPadding = this.afterPadding;
  final double mainAxisPadding = this.mainAxisPadding;
  final double crossAxisPadding = this.crossAxisPadding;
  if (child == null) {
    geometry = SliverGeometry(
      scrollExtent: mainAxisPadding,
      paintExtent: math.min(mainAxisPadding, constraints.remainingPaintExtent),
      maxPaintExtent: mainAxisPadding,
    );
    return;
  }
  child.layout(
    constraints.copyWith(
      scrollOffset: math.max(0.0, constraints.scrollOffset - beforePadding),
      cacheOrigin: math.min(0.0, constraints.cacheOrigin + beforePadding),
      overlap: 0.0,
      remainingPaintExtent: constraints.remainingPaintExtent - calculatePaintOffset(constraints, from: 0.0, to: beforePadding),
      remainingCacheExtent: constraints.remainingCacheExtent - calculateCacheOffset(constraints, from: 0.0, to: beforePadding),
      crossAxisExtent: math.max(0.0, constraints.crossAxisExtent - crossAxisPadding),
    ),
    parentUsesSize: true,
  );
  final SliverGeometry childLayoutGeometry = child.geometry;
  if (childLayoutGeometry.scrollOffsetCorrection != null) {
    geometry = SliverGeometry(
      scrollOffsetCorrection: childLayoutGeometry.scrollOffsetCorrection,
    );
    return;
  }
  final double beforePaddingPaintExtent = calculatePaintOffset(
    constraints,
    from: 0.0,
    to: beforePadding,
  );
  final double afterPaddingPaintExtent = calculatePaintOffset(
    constraints,
    from: beforePadding + childLayoutGeometry.scrollExtent,
    to: mainAxisPadding + childLayoutGeometry.scrollExtent,
  );
  final double mainAxisPaddingPaintExtent = beforePaddingPaintExtent + afterPaddingPaintExtent;
  final double beforePaddingCacheExtent = calculateCacheOffset(
    constraints,
    from: 0.0,
    to: beforePadding,
  );
  final double afterPaddingCacheExtent = calculateCacheOffset(
    constraints,
    from: beforePadding + childLayoutGeometry.scrollExtent,
    to: mainAxisPadding + childLayoutGeometry.scrollExtent,
  );
  final double mainAxisPaddingCacheExtent = afterPaddingCacheExtent + beforePaddingCacheExtent;
  final double paintExtent = math.min(
    beforePaddingPaintExtent + math.max(childLayoutGeometry.paintExtent, childLayoutGeometry.layoutExtent + afterPaddingPaintExtent),
    constraints.remainingPaintExtent,
  );
  geometry = SliverGeometry(
    scrollExtent: mainAxisPadding + childLayoutGeometry.scrollExtent,
    paintExtent: paintExtent,
    layoutExtent: math.min(mainAxisPaddingPaintExtent + childLayoutGeometry.layoutExtent, paintExtent),
    cacheExtent: math.min(mainAxisPaddingCacheExtent + childLayoutGeometry.cacheExtent, constraints.remainingCacheExtent),
    maxPaintExtent: mainAxisPadding + childLayoutGeometry.maxPaintExtent,
    hitTestExtent: math.max(
      mainAxisPaddingPaintExtent + childLayoutGeometry.paintExtent,
      beforePaddingPaintExtent + childLayoutGeometry.hitTestExtent,
    ),
    hasVisualOverflow: childLayoutGeometry.hasVisualOverflow,
  );

  final SliverPhysicalParentData childParentData = child.parentData;
  assert(constraints.axisDirection != null);
  assert(constraints.growthDirection != null);
  switch (applyGrowthDirectionToAxisDirection(constraints.axisDirection, constraints.growthDirection)) {
    case AxisDirection.up:
      childParentData.paintOffset = Offset(_resolvedPadding.left, calculatePaintOffset(constraints, from: _resolvedPadding.bottom + childLayoutGeometry.scrollExtent, to: _resolvedPadding.bottom + childLayoutGeometry.scrollExtent + _resolvedPadding.top));
      break;
    case AxisDirection.right:
      childParentData.paintOffset = Offset(calculatePaintOffset(constraints, from: 0.0, to: _resolvedPadding.left), _resolvedPadding.top);
      break;
    case AxisDirection.down:
      childParentData.paintOffset = Offset(_resolvedPadding.left, calculatePaintOffset(constraints, from: 0.0, to: _resolvedPadding.top));
      break;
    case AxisDirection.left:
      childParentData.paintOffset = Offset(calculatePaintOffset(constraints, from: _resolvedPadding.right + childLayoutGeometry.scrollExtent, to: _resolvedPadding.right + childLayoutGeometry.scrollExtent + _resolvedPadding.left), _resolvedPadding.top);
      break;
  }
  assert(childParentData.paintOffset != null);
  assert(beforePadding == this.beforePadding);
  assert(afterPadding == this.afterPadding);
  assert(mainAxisPadding == this.mainAxisPadding);
  assert(crossAxisPadding == this.crossAxisPadding);
}