computeChildMainAxisPosition method

  1. @override
double computeChildMainAxisPosition (RenderSliver child, double parentMainAxisPosition)
override

Converts the parentMainAxisPosition into the child's coordinate system.

The parentMainAxisPosition is a distance from the top edge (for vertical viewports) or left edge (for horizontal viewports) of the viewport bounds. This describes a line, perpendicular to the viewport's main axis, heretofor known as the target line.

The child's coordinate system's origin in the main axis is at the leading edge of the given child, as given by the child's SliverConstraints.axisDirection and SliverConstraints.growthDirection.

This method returns the distance from the leading edge of the given child to the target line described above.

(The parentMainAxisPosition is not from the leading edge of the viewport, it's always the top or left edge.)

Implementation

@override
double computeChildMainAxisPosition(RenderSliver child, double parentMainAxisPosition) {
  assert(child != null);
  assert(child.constraints != null);
  final SliverPhysicalParentData childParentData = child.parentData;
  switch (applyGrowthDirectionToAxisDirection(child.constraints.axisDirection, child.constraints.growthDirection)) {
    case AxisDirection.down:
      return parentMainAxisPosition - childParentData.paintOffset.dy;
    case AxisDirection.right:
      return parentMainAxisPosition - childParentData.paintOffset.dx;
    case AxisDirection.up:
      return child.geometry.paintExtent - (parentMainAxisPosition - childParentData.paintOffset.dy);
    case AxisDirection.left:
      return child.geometry.paintExtent - (parentMainAxisPosition - childParentData.paintOffset.dx);
  }
  return 0.0;
}