replace method

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

Replaces the parameters of the batch item at the given index. 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.',
  );

  final slot = _requireSlot(index);
  final currentBatchItem = _batchItems[slot];

  currentBatchItem.source = source ?? currentBatchItem.source;
  currentBatchItem.transform = transform ?? currentBatchItem.transform;
  if (color != null) {
    currentBatchItem.color = color;
    currentBatchItem.paint.color = color;
  }

  _sources[slot] = _resolveSourceForAtlas(currentBatchItem);
  _transforms[slot] = currentBatchItem.transform;

  // If color is not explicitly provided, store transparent.
  _colors[slot] = color ?? _defaultColor;
}