value property

  1. @override
double get value
override

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;
  1. @override
set value (dynamic value)
override

Sets the value of this field.

The value can be a double, String, or null.

  • If value is a double or null, it is directly assigned to rawValue.
  • If value is a String, it attempts to parse it into a double using double.tryParse.
    • If parsing succeeds, the parsed double is assigned to rawValue.
    • If parsing fails (e.g., the string is non-numeric), rawValue is set to null.

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;
  }
}