copyList method

List<T> copyList(
  1. Iterable<T> iterable, {
  2. int? length,
  3. T? fillValue,
  4. bool readonly = false,
})

Creates a fixed-length list copy of the iterable, possibly with a modified length and if necessary populated with fillValue.

Implementation

List<T> copyList(Iterable<T> iterable,
    {int? length, T? fillValue, bool readonly = false}) {
  final listLength = iterable.length;
  final result =
      newList(length ?? listLength, fillValue: fillValue ?? defaultValue);
  result.setRange(0, math.min(result.length, listLength), iterable);
  return readonly ? UnmodifiableListView<T>(result) : result;
}