operator []= method
Sets the model object at the specified index.
Provides convenient indexed assignment to list elements. The list must
not be null (asserted at runtime).
Parameters:
index: The zero-based index where the element should be set.value: The new model object of typeTto assign at the index.
Throws: An Exception if:
- rawValue is
null(list not initialized) - The index is out of range (negative or >= list length)
Example:
final field = JsonList<UserModel>('users');
field.value = [user1, user2];
field[0] = newUser; // Replace first element
Implementation
operator []=(int index, value) {
assert(rawValue != null);
if (rawValue == null) {
throw Exception("Index $index is out of range");
}
if (index < 0 || index >= rawValue!.length) {
throw Exception("Index $index is out of range");
}
rawValue![index] = value;
}