adjustDragOffset method Null safety

Offset adjustDragOffset(
  1. Rect targetRect,
  2. Offset point,
  3. {TextDirection direction = TextDirection.ltr}

Adjusts the dragging offset based on the target rect.

This method moves the offsets to be within the target rect in case they are outside the rect.

This is used in the case where a drag happens outside of the rectangle of a Selectable.

The logic works as the following:

For points inside the rect: Their effective locations are unchanged.

For points in Area 1: Move them to top-left of the rect if text direction is ltr, or top-right if rtl.

For points in Area 2: Move them to bottom-right of the rect if text direction is ltr, or bottom-left if rtl.


static Offset adjustDragOffset(Rect targetRect, Offset point, {TextDirection direction = TextDirection.ltr}) {
  if (targetRect.contains(point)) {
    return point;
  if (point.dy <= ||
      point.dy <= targetRect.bottom && point.dx <= targetRect.left) {
    // Area 1
    return direction == TextDirection.ltr ? targetRect.topLeft : targetRect.topRight;
  } else {
    // Area 2
    return direction == TextDirection.ltr ? targetRect.bottomRight : targetRect.bottomLeft;