reorder method

void reorder(
  1. int oldIndex,
  2. int newIndex
)
inherited

Takes a controller at oldIndex and inserts it at newIndex.

This is designed for use with Flutter's built-in ReorderableListView widget. See its docs for help on indexes.

Implementation

void reorder(int oldIndex, int newIndex) {
  // Removing the item at oldIndex will shorten the list by 1.
  final fixedNewIndex = (oldIndex < newIndex) ? newIndex - 1 : newIndex;

  final controller = _itemControllers.removeAt(oldIndex);
  _itemControllers.insert(fixedNewIndex, controller);
  notifyListeners();
}