method insertAll


void insertAll(int index, Iterable<E> iterable)

Inserts all objects of iterable at position index in this list.

This increases the length of the list by the length of iterable and shifts all later objects towards the end of the list.

An error occurs if the index is less than 0 or greater than length. An UnsupportedError occurs if the list is fixed-length.

Source

void insertAll(int index, Iterable<E> iterable) {
  if (index < 0 || index > length) {
    throw new RangeError.range(index, 0, length);
  }
  // TODO(floitsch): we can probably detect more cases.
  if (iterable is! List && iterable is! Set) {
    iterable = iterable.toList();
  }
  int insertionLength = iterable.length;
  // There might be errors after the length change, in which case the list
  // will end up being modified but the operation not complete. Unless we
  // always go through a "toList" we can't really avoid that.
  int len = _list.length;
  _list.length += insertionLength;

  _list.setRange(index + insertionLength, this.length, this, index);
  _list.setAll(index, iterable);

  _notifyChangeLength(len, _list.length);

  if (hasListObservers && insertionLength > 0) {
    _recordChange(new ListChangeRecord(this, index,
        addedCount: insertionLength));
  }
}