copyWithReplacedAt method
Returns a copy with the element at index replaced
Implementation
List<T> copyWithReplacedAt(int index, T newItem) {
if (index < 0 || index >= length) {
throw RangeError('Index $index out of bounds for list of length $length');
}
return [...sublist(0, index), newItem, ...sublist(index + 1)];
}