drag method

Future<void> drag(
  1. FinderBase<Element> finder,
  2. Offset offset,
  3. {int? pointer,
  4. int buttons = kPrimaryButton,
  5. double touchSlopX = kDragSlopDefault,
  6. double touchSlopY = kDragSlopDefault,
  7. bool warnIfMissed = true,
  8. PointerDeviceKind kind = PointerDeviceKind.touch}
)

Attempts to drag the given widget by the given offset, by starting a drag in the middle of the widget.

The warnIfMissed argument, if true (the default), causes a warning to be displayed on the console if the specified Finder indicates a widget and location that, were a pointer event to be sent to that location, would not actually send any events to the widget (e.g. because the widget is obscured, or the location is off-screen, or the widget is transparent to pointer events).

Set the argument to false to silence that warning if you intend to not actually hit the specified element.

If you want the drag to end with a speed so that the gesture recognition system identifies the gesture as a fling, consider using fling instead.

The operation happens at once. If you want the drag to last for a period of time, consider using timedDrag.

The offset represents a distance the pointer moves in the global coordinate system of the screen.

Positive Offset.dy values mean the pointer moves downward. Negative Offset.dy values mean the pointer moves upwards. Accordingly, positive Offset.dx values mean the pointer moves towards the right. Negative Offset.dx values mean the pointer moves towards left.

By default, if the x or y component of offset is greater than kDragSlopDefault, the gesture is broken up into two separate moves calls. Changing touchSlopX or touchSlopY will change the minimum amount of movement in the respective axis before the drag will be broken into multiple calls. To always send the drag with just a single call to TestGesture.moveBy, touchSlopX and touchSlopY should be set to 0.

Breaking the drag into multiple moves is necessary for accurate execution of drag update calls with a DragStartBehavior variable set to DragStartBehavior.start. Without such a change, the dragUpdate callback from a drag recognizer will never be invoked.

To force this function to a send a single move event, the touchSlopX and touchSlopY variables should be set to 0. However, generally, these values should be left to their default values.

Implementation

Future<void> drag(
  finders.FinderBase<Element> finder,
  Offset offset, {
  int? pointer,
  int buttons = kPrimaryButton,
  double touchSlopX = kDragSlopDefault,
  double touchSlopY = kDragSlopDefault,
  bool warnIfMissed = true,
  PointerDeviceKind kind = PointerDeviceKind.touch,
}) {
  return dragFrom(
    getCenter(finder, warnIfMissed: warnIfMissed, callee: 'drag'),
    offset,
    pointer: pointer,
    buttons: buttons,
    touchSlopX: touchSlopX,
    touchSlopY: touchSlopY,
    kind: kind,
  );
}