resize method

void resize(
  1. int length, {
  2. bool clearNewCells = false,
})

Implementation

void resize(int length, {bool clearNewCells = false}) {
  assert(length >= 0);

  if (length == _length) {
    return;
  }

  final oldLength = _length;
  if (length > _length) {
    final newBufferSize = _calcCapacity(length) * _cellSize;

    if (newBufferSize > _data.length) {
      final newBuffer = Uint32List(newBufferSize);
      newBuffer.setRange(0, _data.length, _data);
      _data = newBuffer;
    }
  }

  _length = length;
  if (clearNewCells && length > oldLength) {
    for (var i = oldLength; i < length; i++) {
      resetCell(i);
    }
  }

  for (var i = 0; i < _anchors.length; i++) {
    final anchor = _anchors[i];
    if (anchor.x > _length) {
      anchor.reposition(_length);
    }
  }
}