copyWithInserted method

List<T> copyWithInserted(
  1. int index,
  2. T item
)

Returns a copy with item inserted at index

Implementation

List<T> copyWithInserted(int index, T item) {
  if (index < 0 || index > length) {
    throw RangeError('Index $index out of bounds for list of length $length');
  }
  return [...sublist(0, index), item, ...sublist(index)];
}