changeItemPosition static method

void changeItemPosition(
  1. List<DraggableAnimationItem> menuList,
  2. DraggableAnimationItem fromMenu,
  3. DraggableAnimationItem toMenu
)

Implementation

static void changeItemPosition(
  List<DraggableAnimationItem> menuList,
  DraggableAnimationItem fromMenu,
  DraggableAnimationItem toMenu
){
  int fromIndex = menuList.indexWhere((e) => e.id == fromMenu.id);
  int toIndex = menuList.indexWhere((e) => e.id == toMenu.id);
  if (fromIndex == -1 || toIndex == -1) {
    print('One or both items not found in the list.');
    return;
  }
  var removedItem = menuList.removeAt(fromIndex);
  menuList.insert(toIndex, removedItem);
}