operator [] method
Retrieves the model object at the specified index.
Provides convenient indexed access to list elements. Returns null if
the list is null, otherwise returns the element at the given index.
Parameters:
index: The zero-based index of the element to retrieve.
Returns:
The model object of type T at the specified index, or null if
rawValue is null.
Throws: An Exception if the index is out of range (negative or >= list length).
Example:
final field = JsonList<UserModel>('users');
field.value = [user1, user2];
print(field[0]['name']); // Access first user's name
Implementation
operator [](int index) {
if (rawValue == null) {
return null;
}
if (index < 0 || index >= rawValue!.length) {
throw Exception("Index $index is out of range");
}
return rawValue![index];
}