operator []= method Null safety

void operator []=(
  1. int index,
  2. dynamic newVal
)

Implementation

operator []=(int index, newVal) {
  if (index == 0) {
    item1 = newVal;
  } else if (index == 1) {
    item2 = newVal;
  } else if (index < 0) {
    this[(index % 2)] = newVal;
  }
  throw RangeError('$index is out of range (only 1 and 2)');
}