Sortable<T> constructor
const
Sortable<T> ({
- Key? key,
- bool enabled = true,
- required SortableData<
T> data, - Predicate<
SortableData< ? canAcceptTop,T> > - Predicate<
SortableData< ? canAcceptLeft,T> > - Predicate<
SortableData< ? canAcceptRight,T> > - Predicate<
SortableData< ? canAcceptBottom,T> > - ValueChanged<
SortableData< ? onAcceptTop,T> > - ValueChanged<
SortableData< ? onAcceptLeft,T> > - ValueChanged<
SortableData< ? onAcceptRight,T> > - ValueChanged<
SortableData< ? onAcceptBottom,T> > - Widget? placeholder = const SizedBox(),
- Widget? ghost,
- Widget? fallback,
- Widget? candidateFallback,
- VoidCallback? onDragStart,
- VoidCallback? onDragEnd,
- VoidCallback? onDragCancel,
- HitTestBehavior behavior = HitTestBehavior.deferToChild,
- VoidCallback? onDropFailed,
- 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 treedata(SortableData<T>, required): Data associated with this sortable itemchild(Widget, required): The main widget to make sortableenabled(bool, default: true): Whether drag interactions are enabledcanAcceptTop(Predicate<SortableData<T>>?, optional): Validation for top dropscanAcceptLeft(Predicate<SortableData<T>>?, optional): Validation for left dropscanAcceptRight(Predicate<SortableData<T>>?, optional): Validation for right dropscanAcceptBottom(Predicate<SortableData<T>>?, optional): Validation for bottom dropsonAcceptTop(ValueChanged<SortableData<T>>?, optional): Handler for top dropsonAcceptLeft(ValueChanged<SortableData<T>>?, optional): Handler for left dropsonAcceptRight(ValueChanged<SortableData<T>>?, optional): Handler for right dropsonAcceptBottom(ValueChanged<SortableData<T>>?, optional): Handler for bottom dropsplaceholder(Widget?, default: SizedBox()): Widget shown in drop zonesghost(Widget?, optional): Widget displayed while draggingfallback(Widget?, optional): Widget shown at original position during dragcandidateFallback(Widget?, optional): Widget shown when item is drop candidateonDragStart(VoidCallback?, optional): Called when drag startsonDragEnd(VoidCallback?, optional): Called when drag ends successfullyonDragCancel(VoidCallback?, optional): Called when drag is cancelledbehavior(HitTestBehavior, default: HitTestBehavior.deferToChild): Hit test behavioronDropFailed(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,
});