startItemDragReorder method

void startItemDragReorder({
  1. required int index,
  2. required PointerDownEvent event,
  3. required MultiDragGestureRecognizer recognizer,
})

Initiate the dragging of the item at index that was started with the pointer down event.

The given recognizer will be used to recognize and start the drag item tracking and lead to either an item reorder, or a canceled drag.

Most applications will not use this directly, but will wrap the item (or part of the item, like a drag handle) in either a ReorderableDragStartListener or ReorderableDelayedDragStartListener which call this method when they detect the gesture that triggers a drag start.

Implementation

void startItemDragReorder({
  required int index,
  required PointerDownEvent event,
  required MultiDragGestureRecognizer recognizer,
}) {
  assert(0 <= index && index < widget.itemCount);
  setState(() {
    if (_dragInfo != null) {
      cancelReorder();
    } else if (_recognizer != null && _recognizerPointer != event.pointer) {
      _recognizer!.dispose();
      _recognizer = null;
      _recognizerPointer = null;
    }

    if (_items.containsKey(index)) {
      _dragIndex = index;
      _recognizer = recognizer
        ..onStart = _dragStart
        ..addPointer(event);
      _recognizerPointer = event.pointer;
    } else {
      // TODO(darrenaustin): Can we handle this better, maybe scroll to the item?
      throw Exception('Attempting to start a drag on a non-visible item');
    }
  });
}