replace method

void replace(
  1. int index, {
  2. Rect? source,
  3. Color? color,
  4. RSTransform? transform,
})

Replace provided values of a batch item at the index, when a parameter is not provided, the original value of the batch item will be used.

Throws an ArgumentError if the index is out of bounds. At least one of the parameters must be different from null.

Implementation

void replace(
  int index, {
  Rect? source,
  Color? color,
  RSTransform? transform,
}) {
  assert(
    source != null || color != null || transform != null,
    'At least one of the parameters must be different from null.',
  );

  if (index < 0 || index >= length) {
    throw ArgumentError('Index out of bounds: $index');
  }

  final currentBatchItem = _batchItems[index];
  final newBatchItem = BatchItem(
    source: source ?? currentBatchItem.source,
    transform: transform ?? currentBatchItem.transform,
    color: color ?? currentBatchItem.paint.color,
    flip: currentBatchItem.flip,
  );

  _batchItems[index] = newBatchItem;

  _sources[index] = newBatchItem.source;
  _transforms[index] = newBatchItem.transform;
  _colors[index] = color ?? _defaultColor;
}