childMainAxisPosition method

  1. @override
double childMainAxisPosition(
  1. RenderObject child
)
override

The math in this method is a the heart of positioning the children. It is important to realize that the body sliver is doing its own scrolling and needs to be positioned like a window.

Implementation

@override
// ignore: missing_return
double childMainAxisPosition(RenderObject child) {
  if (reverse) {
    if (child == _header) {
      return min(
        max(0, constraints.remainingPaintExtent - _headerExtent),
        (overlayHeader ? _bodyExtent - _headerExtent : _bodyExtent) -
            constraints.scrollOffset,
      );
    } else if (child == _body) {
      return 0;
    }
  } else {
    if (child == _header) {
      return min(
          0,
          (overlayHeader ? _bodyExtent - _headerExtent : _bodyExtent) -
              constraints.scrollOffset);
    } else if (child == _body) {
      return overlayHeader
          ? 0
          : max(0, _headerExtent - constraints.scrollOffset);
    }
  }

  throw ArgumentError.value(
    child,
    'child',
    'must be either _header or _body',
  );
}