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() {
  // ensure we have header and content boxes
  assert(childCount == 2);
  // layout both header and content widget
  final childConstraints = constraints.loosen();
  _headerBox?.layout(childConstraints, parentUsesSize: true);
  _contentBox?.layout(childConstraints, parentUsesSize: true);
  final headerHeight = _headerBox?.size.height ?? 0;
  final contentHeight = _contentBox?.size.height ?? 0;
  // determine size of ourselves based on content widget
  final width = max(constraints.minWidth, _contentBox?.size.width ?? 0);
  final height = max(constraints.minHeight, _overlapHeaders ? contentHeight : headerHeight + contentHeight);
  size = new Size(width, height);
  assert(size.width == constraints.constrainWidth(width));
  assert(size.height == constraints.constrainHeight(height));
  assert(size.isFinite);
  // place content underneath header
  final contentParentData = _contentBox?.parentData as MultiChildLayoutParentData;
  contentParentData.offset = new Offset(0.0, _overlapHeaders ? 0.0 : headerHeight);
  // determine by how much the header should be stuck to the top
  final double stuckOffset = determineStuckOffset();
  // place header over content relative to scroll offset
  final double maxOffset = height - headerHeight;
  final headerParentData = _headerBox?.parentData as MultiChildLayoutParentData;
  headerParentData.offset = new Offset(0.0, max(0.0, min(-stuckOffset, maxOffset)));
  // report to widget how much the header is stuck.
  if (_callback != null) {
    final stuckAmount = max(min(headerHeight, stuckOffset), -headerHeight) / headerHeight;
    _callback!(stuckAmount);
  }
}