value property
Gets the double value of this field.
If the underlying rawValue is null
, this getter returns 0.0
by default.
This ensures that the field always provides a double value when accessed.
Implementation
@override
double get value => rawValue ?? 0;
Sets the value of this field.
The value
can be a double
, String
, or null
.
- If
value
is adouble
ornull
, it is directly assigned to rawValue. - If
value
is aString
, it attempts to parse it into adouble
usingdouble.tryParse
.
Examples:
JsonDouble priceField = JsonDouble("price");
// Setting with a double
priceField.value = 19.99; // rawValue is 19.99
// Setting with a numeric string
priceField.value = "29.99"; // rawValue is 29.99
// Setting with a non-numeric string
priceField.value = "abc"; // rawValue is null
Implementation
@override
set value(dynamic value) {
if (value is double?) {
rawValue = value;
return;
}
if (value is String) {
rawValue = double.tryParse(value);
return;
}
}