move method
Moves an element in a list to another position.
fromIndex
and toIndex
both point to the places in the old array.
Implementation
void move({required int fromIndex, required int toIndex}) {
final maxIndex = value.length <= 2 ? value.length - 1 : value.length;
toIndex = min(toIndex, maxIndex);
final newToIndex = value.length <= 2
? toIndex
: fromIndex < toIndex
? toIndex - 1
: toIndex;
final oldValue = value;
final newValue = [...oldValue];
final element = newValue.removeAt(fromIndex);
newValue.insert(newToIndex, element);
final change = GgChange(
oldValue: oldValue,
newValue: newValue,
type: GgChangeType.move,
oldIndex: fromIndex,
index: newToIndex,
);
_syncAndApplyChange(change);
}