startItemDragReorder method Null safety

void startItemDragReorder (
  1. {required int index,
  2. required PointerDownEvent event,
  3. required MultiDragGestureRecognizer<MultiDragPointerState> 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 cancelled 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<MultiDragPointerState> recognizer,
}) {
  assert(0 <= index && index < widget.itemCount);
  setState(() {
    if (_reorderingDrag) {
      cancelReorder();
    }
    if (_items.containsKey(index)) {
      _dragItem = _items[index]!;
      _recognizer = recognizer
        ..onStart = _dragStart
        ..addPointer(event);
    } 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');
    }
  });
}