mutableString method

MutableCell<String> mutableString({
  1. ValueCell<double> errorValue = const ValueCell.value(0.0),
})

Return a cell which evaluates to a string representation of this cell's value.

The returned cell is a mutable computed cell. If the value of the returned cell is set explicitly, a double is parsed from the assigned string value and is assigned to this cell's value.

errorValue is the value to assign to this cell when there is an error parsing a a double from the string.

Note errorValue is a ValueCell to allow the default value to be chosen dynamically. If a constant is required use the NumValueCellExtension.cell property e.g. 1.0.cell.

Pitfalls:

A binding is not established between errorValue and this cell. This means that this cell will not react to changes in errorValue. Only the value at the time of assigning a value to the returned cell are used.

Implementation

MutableCell<String> mutableString({
  ValueCell<double> errorValue = const ValueCell.value(0.0),
}) => MutableComputeCell(
    arguments: {this},
    compute: () => value.toString(),
    reverseCompute: (value) {
      this.value = double.tryParse(value) ?? errorValue.value;
    },
);