Sortable<T> constructor

const Sortable<T>({
  1. Key? key,
  2. bool enabled = true,
  3. required SortableData<T> data,
  4. Predicate<SortableData<T>>? canAcceptTop,
  5. Predicate<SortableData<T>>? canAcceptLeft,
  6. Predicate<SortableData<T>>? canAcceptRight,
  7. Predicate<SortableData<T>>? canAcceptBottom,
  8. ValueChanged<SortableData<T>>? onAcceptTop,
  9. ValueChanged<SortableData<T>>? onAcceptLeft,
  10. ValueChanged<SortableData<T>>? onAcceptRight,
  11. ValueChanged<SortableData<T>>? onAcceptBottom,
  12. Widget? placeholder = const SizedBox(),
  13. Widget? ghost,
  14. Widget? fallback,
  15. Widget? candidateFallback,
  16. VoidCallback? onDragStart,
  17. VoidCallback? onDragEnd,
  18. VoidCallback? onDragCancel,
  19. HitTestBehavior behavior = HitTestBehavior.deferToChild,
  20. VoidCallback? onDropFailed,
  21. required Widget child,
})

Creates a Sortable widget with drag-and-drop functionality.

Configures a widget that can be dragged and accepts drops from other sortable items. The widget supports directional drop zones and provides extensive customization for drag interactions and visual feedback.

Parameters:

  • key (Key?): Widget identifier for the widget tree
  • data (SortableData<T>, required): Data associated with this sortable item
  • child (Widget, required): The main widget to make sortable
  • enabled (bool, default: true): Whether drag interactions are enabled
  • canAcceptTop (Predicate<SortableData<T>>?, optional): Validation for top drops
  • canAcceptLeft (Predicate<SortableData<T>>?, optional): Validation for left drops
  • canAcceptRight (Predicate<SortableData<T>>?, optional): Validation for right drops
  • canAcceptBottom (Predicate<SortableData<T>>?, optional): Validation for bottom drops
  • onAcceptTop (ValueChanged<SortableData<T>>?, optional): Handler for top drops
  • onAcceptLeft (ValueChanged<SortableData<T>>?, optional): Handler for left drops
  • onAcceptRight (ValueChanged<SortableData<T>>?, optional): Handler for right drops
  • onAcceptBottom (ValueChanged<SortableData<T>>?, optional): Handler for bottom drops
  • placeholder (Widget?, default: SizedBox()): Widget shown in drop zones
  • ghost (Widget?, optional): Widget displayed while dragging
  • fallback (Widget?, optional): Widget shown at original position during drag
  • candidateFallback (Widget?, optional): Widget shown when item is drop candidate
  • onDragStart (VoidCallback?, optional): Called when drag starts
  • onDragEnd (VoidCallback?, optional): Called when drag ends successfully
  • onDragCancel (VoidCallback?, optional): Called when drag is cancelled
  • behavior (HitTestBehavior, default: HitTestBehavior.deferToChild): Hit test behavior
  • onDropFailed (VoidCallback?, optional): Called when drop fails

Example:

Sortable<String>(
  data: SortableData('item_1'),
  onAcceptTop: (data) => moveAbove(data.data),
  onAcceptBottom: (data) => moveBelow(data.data),
  placeholder: Container(height: 2, color: Colors.blue),
  child: ListTile(title: Text('Draggable Item')),
)

Implementation

const Sortable({
  super.key,
  this.enabled = true,
  required this.data,
  this.canAcceptTop,
  this.canAcceptLeft,
  this.canAcceptRight,
  this.canAcceptBottom,
  this.onAcceptTop,
  this.onAcceptLeft,
  this.onAcceptRight,
  this.onAcceptBottom,
  this.placeholder = const SizedBox(),
  this.ghost,
  this.fallback,
  this.candidateFallback,
  this.onDragStart,
  this.onDragEnd,
  this.onDragCancel,
  this.behavior = HitTestBehavior.deferToChild,
  this.onDropFailed,
  required this.child,
});