value property
Returns the integer value of this field.
If the underlying rawValue is null, this getter returns 0 as
a default value. This ensures that integer fields always provide a
valid integer value when accessed, which is useful for calculations.
Returns:
The integer value, or 0 if rawValue is null.
Example:
final field = JsonInteger('age');
print(field.value); // 0 (default)
field.value = 25;
print(field.value); // 25
Implementation
@override
int get value => rawValue ?? 0;
Sets the integer value, accepting both integers and numeric strings.
This setter provides flexible input handling:
intornull: Assigned directly to rawValueString: Parsed usingint.tryParse(). If parsing fails (e.g., non-numeric string), rawValue is set tonull
Parameters:
value: The value to set, which can be anint, a numericString, ornull.
Example:
final field = JsonInteger('age');
field.value = 25; // Direct integer
field.value = "30"; // String → 30
field.value = "invalid"; // Sets rawValue to null
Implementation
@override
set value(dynamic value) {
if (value is int?) {
rawValue = value;
return;
}
if (value is String) {
rawValue = int.tryParse(value);
return;
}
}