mutableString method

MutableCell<String> mutableString({
  1. ValueCell<int> 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, an integer 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 an integer from the string.

Note errorValue is a ValueCell's to allow the default value to be chosen dynamically. If a constant is required use the NumValueCellExtension.cell property e.g. 10.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 values at the time of assigning a value to the returned cell are used.

Implementation

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