mutableString method

MutableCell<String> mutableString({
  1. ValueCell<num> errorValue = const ValueCell.value(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 num 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 num 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<num> errorValue = const ValueCell.value(0),
}) => MutableComputeCell(
    arguments: {this},
    compute: () => value.toString(),
    reverseCompute: (value) {
      this.value = num.tryParse(value) ?? errorValue.value;
    }
);