computeAbsolutePaintOffsetFor method

  1. @protected
Offset computeAbsolutePaintOffsetFor(
  1. RenderBox child,
  2. {required Offset layoutOffset}
)

The offset at which the given child should be painted.

The returned offset is from the top left corner of the inside of the viewport to the top left corner of the paint coordinate system of the child.

This is useful when the one or both of the axes of the viewport are reversed. The normalized layout offset of the child is used to compute the paint offset in relation to the verticalAxisDirection and horizontalAxisDirection.

Implementation

@protected
Offset computeAbsolutePaintOffsetFor(
  RenderBox child, {
  required Offset layoutOffset,
}) {
  // This is only usable once we have sizes.
  assert(hasSize);
  assert(child.hasSize);
  final double xOffset;
  final double yOffset;
  switch (verticalAxisDirection) {
    case AxisDirection.up:
      yOffset = viewportDimension.height - (layoutOffset.dy + child.size.height);
    case AxisDirection.down:
      yOffset = layoutOffset.dy;
    case AxisDirection.right:
    case AxisDirection.left:
      throw Exception('This should not happen');
  }
  switch (horizontalAxisDirection) {
    case AxisDirection.right:
      xOffset = layoutOffset.dx;
    case AxisDirection.left:
      xOffset = viewportDimension.width - (layoutOffset.dx + child.size.width);
    case AxisDirection.up:
    case AxisDirection.down:
      throw Exception('This should not happen');
  }
  return Offset(xOffset, yOffset);
}