operator []= method
Sets the value of a nested field within the model object.
Provides convenient assignment to fields within the nested model using
bracket notation. This delegates to the model's []= operator. The
model object must not be null (asserted at runtime).
Parameters:
name: The name of the nested field to set (must match a field's JsonField.fieldName in the nested model).value: The new value to assign to the nested field.
Throws: An Exception if:
- The model object is
null - No field with the given name exists in the nested model
Example:
final field = JsonObject<AddressModel>('address');
field.value = addressModel;
field['zipCode'] = '10001'; // Set nested field value
Implementation
operator []=(String name, value) {
assert(rawValue != null);
if (rawValue == null) {
throw Exception("Field $name does not exist");
}
for (final field in rawValue!.fields) {
if (field.fieldName == name) {
field.value = value;
return;
}
}
throw Exception("Field $name does not exist");
}