getNearestPoint method

Offset getNearestPoint(
  1. Offset offset
)

Get the nearest corner from {offset}

Implementation

Offset getNearestPoint(Offset offset) {
  // Clamp the x-coordinate of the offset within the rect's horizontal boundaries
  final nearestX = offset.dx.clamp(left, right);

  // Clamp the y-coordinate of the offset within the rect's vertical boundaries
  final nearestY = offset.dy.clamp(top, bottom);

  // Return the nearest corner
  return Offset(nearestX, nearestY);
}