operator [] method
Retrieves the value of a field by its name using bracket notation.
This operator provides convenient access to field values without needing
to iterate through the fields list manually. The returned value is
the typed value from the field (e.g., String for JsonString,
int for JsonInteger).
Parameters:
name: The name of the field to retrieve (must match a field's JsonField.fieldName).
Returns:
The value of the field, which may be the field's default value if
rawValue is null (see individual field type documentation).
Throws: An Exception if no field with the given name exists in this model.
Example:
final name = user['name']; // Returns String value
final age = user['age']; // Returns int value
Implementation
operator [](String name) {
for (final field in fields) {
if (field.fieldName == name) {
return field.value;
}
}
throw Exception("Field $name does not exist");
}