operator []= method

void operator []=(
  1. int index,
  2. T value
)

Sets the value at the specified index in the array. If the index is out of range, an exception is thrown. index The index at which to set the value. value The value to set at the specified index. Example:

ModelLessArray<int> array = ModelLessArray<int>();
array.set(1);
array.set(2);
array.set(3);
array[1] = 5; // Sets the value at index 1 to 5
print(array[1]); // Outputs: 5

Throws an Exception if the index is out of range.

Implementation

void operator []=(int index, T value) {
  fields ??= <T>[];
  if (fields!.length <= index) {
    throw Exception('Index out of range: $index');
  } else {
    fields![index] = value;
  }
}