handlePanUpdate method Null safety

void handlePanUpdate(
  1. DragUpdateDetails details
)
override

Is called when a pan gesture is updated.

See also:

Implementation

void handlePanUpdate(DragUpdateDetails details) {
  final center = Offset(
    size.width / 2,
    Math.min(size.width, size.height) / 2,
  );
  bool onTop = details.localPosition.dy <= center.dy;
  bool onLeftSide = details.localPosition.dx <= center.dx;
  bool onRightSide = !onLeftSide;
  bool onBottom = !onTop;

  bool panUp = details.delta.dy <= 0.0;
  bool panLeft = details.delta.dx <= 0.0;
  bool panRight = !panLeft;
  bool panDown = !panUp;

  double yChange = details.delta.dy.abs();
  double xChange = details.delta.dx.abs();

  double verticalRotation = (onRightSide && panDown) || (onLeftSide && panUp)
      ? yChange
      : yChange * -1;

  double horizontalRotation =
      (onTop && panRight) || (onBottom && panLeft) ? xChange : xChange * -1;

  double rotationalChange = verticalRotation + horizontalRotation;

  value = value.copyWith(distance: value.distance + rotationalChange);
}