layoutChild method

  1. @protected
void layoutChild(
  1. double scrollOffset,
  2. double maxExtent, {
  3. bool overlapsContent = false,
})

Lays out the child.

This is called by performLayout. It applies the given scrollOffset (which need not match the offset given by the constraints) and the maxExtent (which need not match the value returned by the maxExtent getter).

The overlapsContent argument is passed to updateChild.

Implementation

@protected
void layoutChild(double scrollOffset, double maxExtent, { bool overlapsContent = false }) {
  final double shrinkOffset = math.min(scrollOffset, maxExtent);
  if (_needsUpdateChild || _lastShrinkOffset != shrinkOffset || _lastOverlapsContent != overlapsContent) {
    invokeLayoutCallback<SliverConstraints>((SliverConstraints constraints) {
      assert(constraints == this.constraints);
      updateChild(shrinkOffset, overlapsContent);
    });
    _lastShrinkOffset = shrinkOffset;
    _lastOverlapsContent = overlapsContent;
    _needsUpdateChild = false;
  }
  assert(() {
    if (minExtent <= maxExtent) {
      return true;
    }
    throw FlutterError.fromParts(<DiagnosticsNode>[
      ErrorSummary('The maxExtent for this $runtimeType is less than its minExtent.'),
      DoubleProperty('The specified maxExtent was', maxExtent),
      DoubleProperty('The specified minExtent was', minExtent),
    ]);
  }());
  double stretchOffset = 0.0;
  if (stretchConfiguration != null && constraints.scrollOffset == 0.0) {
    stretchOffset += constraints.overlap.abs();
  }

  child?.layout(
    constraints.asBoxConstraints(
      maxExtent: math.max(minExtent, maxExtent - shrinkOffset) + stretchOffset,
    ),
    parentUsesSize: true,
  );

  if (stretchConfiguration != null &&
    stretchConfiguration!.onStretchTrigger != null &&
    stretchOffset >= stretchConfiguration!.stretchTriggerOffset &&
    _lastStretchOffset <= stretchConfiguration!.stretchTriggerOffset) {
    stretchConfiguration!.onStretchTrigger!();
  }
  _lastStretchOffset = stretchOffset;
}