wrapOffset method

  1. @override
SliverOffset wrapOffset(
  1. Offset offset,
  2. Size size
)
override

Wraps an Offset into a SliverOffset using the sliver constraints of this boxy.

If this boxy is not a RenderSliver, assume the axis is vertical.

Implementation

@override
SliverOffset wrapOffset(Offset offset, Size size) {
  double main;
  final double cross;
  var reversed = false;
  switch (constraints.axisDirection) {
    case AxisDirection.up:
      cross = offset.dx;
      main = offset.dy;
      reversed = true;
      break;
    case AxisDirection.down:
      cross = offset.dx;
      main = offset.dy;
      reversed = false;
      break;
    case AxisDirection.right:
      cross = offset.dy;
      main = offset.dx;
      reversed = false;
      break;
    case AxisDirection.left:
      cross = offset.dy;
      main = offset.dx;
      reversed = true;
      break;
  }
  if (constraints.growthDirection == GrowthDirection.reverse) {
    reversed = !reversed;
  }
  if (reversed) {
    switch (constraints.axis) {
      case Axis.horizontal:
        main = size.width - main;
        break;
      case Axis.vertical:
        main = size.height - main;
        break;
    }
  }
  return SliverOffset(offset.dx, offset.dy, cross, main);
}