arrMove function

List arrMove(
  1. List array,
  2. int from,
  3. int to
)

Moves the position of a specific element in an array to the specified position. (Position starts from 0.)

Implementation

List<dynamic> arrMove(List<dynamic> array, int from, int to) {
  final int arrayLength = array.length;

  if (arrayLength <= from || arrayLength <= to) {
    throw Exception('Invalid move params');
  }

  final dynamic item = array.removeAt(from);
  array.insert(to, item);

  return array;
}