ReorderCallback typedef

ReorderCallback = void Function(int oldIndex, int newIndex)

A callback used by ReorderableList to report that a list item has moved to a new position in the list.

Implementations should remove the corresponding list item at oldIndex and reinsert it at newIndex.

If oldIndex is before newIndex, removing the item at oldIndex from the list will reduce the list's length by one. Implementations will need to account for this when inserting before newIndex.

link
final List<MyDataObject> backingList = <MyDataObject>[/* ... */];

void handleReorder(int oldIndex, int newIndex) {
  if (oldIndex < newIndex) {
    // removing the item at oldIndex will shorten the list by 1.
    newIndex -= 1;
  }
  final MyDataObject element = backingList.removeAt(oldIndex);
  backingList.insert(newIndex, element);
}

See also:

Implementation

typedef ReorderCallback = void Function(int oldIndex, int newIndex);