setDraggable method

Widget setDraggable({
  1. required T data,
  2. required Widget father,
  3. required Key key,
})

Implementation

Widget setDraggable({required T data, required Widget father, required Key key}) {
  Widget child = setDragScope(data, father, key);
  int maxSimultaneousDrags = widget.maxSimultaneousDrags;
  if (maxSimultaneousDrags == 1 && dragData != null && dragData != data) {
    maxSimultaneousDrags = 0;
  }
  if (widget.isDrag && !isContains(data)) {
    if (widget.isLongPressDraggable) {
      child = DragLongPressDraggable<T>(
        feedback: setFeedback(data, father, key),
        maxSimultaneousDrags: maxSimultaneousDrags,
        axis: widget.axis,
        data: data,
        onDragStarted: () {
          if (DragAnimNotification.isScroll) {
            return;
          }
          dragData = data;
          setDragStart();
          widget.onDragStarted?.call(data);
        },
        dragAnchorStrategy: widget.dragAnchorStrategy,
        onDragUpdate: (DragUpdateDetails details) {
          if (widget.isEdgeScroll) {
            _autoScrollIfNecessary(details.globalPosition);
          }
          widget.onDragUpdate?.call(details, data);
        },
        onDraggableCanceled: (Velocity velocity, Offset offset) {
          setDragStart(isDragStart: false);
          endAnimation();
          widget.onDraggableCanceled?.call(velocity, offset, data);
        },
        onDragEnd: (DraggableDetails details) {
          setDragStart(isDragStart: false);
          widget.onDragEnd?.call(details, data);
        },
        onDragCompleted: () {
          setDragStart(isDragStart: false);
          endAnimation();
          widget.onDragCompleted?.call(data);
        },
        delay: widget.longPressDelay ?? const Duration(milliseconds: 500),
        child: child,
      );
    } else {
      child = DragDraggable<T>(
        feedback: setFeedback(data, father, key),
        maxSimultaneousDrags: maxSimultaneousDrags,
        axis: widget.axis,
        data: data,
        onDragStarted: () {
          dragData = data;
          setDragStart();
          widget.onDragStarted?.call(data);
        },
        dragAnchorStrategy: widget.dragAnchorStrategy,
        onDragUpdate: (DragUpdateDetails details) {
          if (widget.isEdgeScroll) {
            _autoScrollIfNecessary(details.globalPosition);
          }
          widget.onDragUpdate?.call(details, data);
        },
        onDraggableCanceled: (Velocity velocity, Offset offset) {
          setDragStart(isDragStart: false);
          endAnimation();
          widget.onDraggableCanceled?.call(velocity, offset, data);
        },
        onDragEnd: (DraggableDetails details) {
          setDragStart(isDragStart: false);
          widget.onDragEnd?.call(details, data);
        },
        onDragCompleted: () {
          setDragStart(isDragStart: false);
          endAnimation();
          widget.onDragCompleted?.call(data);
        },
        child: child,
      );
    }
  }
  return child;
}