number<C extends Component> static method

ComponentField<C> number<C extends Component>(
  1. String name, {
  2. required double defaultValue,
  3. double get(
    1. C component
    )?,
  4. void set(
    1. C component,
    2. double value
    )?,
  5. String? doc,
  6. String? group,
  7. List<PropertyConstraint<num>> constraints = const [],
  8. List<String> formerNames = const [],
  9. bool transient = false,
})

A floating-point property.

Implementation

static ComponentField<C> number<C extends Component>(
  String name, {
  required double defaultValue,
  double Function(C component)? get,
  void Function(C component, double value)? set,
  String? doc,
  String? group,
  List<PropertyConstraint<num>> constraints = const [],
  List<String> formerNames = const [],
  bool transient = false,
}) => ComponentField(
  ComponentPropertyDef(
    name,
    ComponentPropertyKind.number,
    defaultValue: DoubleValue(defaultValue),
    doc: doc,
    group: group,
    constraints: constraints,
    formerNames: formerNames,
    transient: transient,
  ),
  read: get == null ? null : (c, _) => DoubleValue(get(c)),
  write: set == null
      ? null
      : (c, v, _) {
          final number = switch (v) {
            DoubleValue(:final value) => value,
            IntValue(:final value) => value.toDouble(),
            _ => null,
          };
          if (number != null) set(c, number);
        },
);