onDragEnded method
void
onDragEnded()
Implementation
void onDragEnded() {
if (dragKey == null) return;
final target = findDropTargetItem();
_onDragEnd = () {
if (_dragIndex != null) {
if (!_itemBoxes.containsKey(target!.key)) {
_measureChild(target.key);
}
final toIndex = _itemBoxes[target.key]?.index;
if (toIndex != null) {
final E item = data.removeAt(_dragIndex!);
data.insert(toIndex, item);
widget.onReorderFinished(
item,
_dragIndex!,
toIndex,
List<E>.from(data),
);
}
}
_cancelReorder();
};
_items[dragKey]?.duration = widget.settleDuration;
final delta = () {
if (target == dragItem) {
return -_pointerDelta;
} else if (_up) {
return target!.start - _dragStart;
} else {
return target!.end - _dragEnd;
}
}();
_dispatchMove(
dragKey,
// Make sure not to pass a zero delta (i.e. the item didn't move)
// as this would lead to the same upper and lower bound on the animation
// controller, which is not allowed.
delta != 0.0 ? delta : 0.5,
onEnd: _onDragEnd,
duration: widget.settleDuration,
);
avoidConflictingMoves(target);
_scrollAdjuster?.cancel();
setState(() => _inDrag = false);
}