mutableString method
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.
format is of type NumberFormat and is used to format the string
representation of the num value.
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),
NumberFormat? format,
}) =>
MutableComputeCell(
arguments: {this},
compute: () => format?.format(value) ?? value.toString(),
reverseCompute: (value) {
this.value = format?.tryParse(value)?.toDouble() ??
double.tryParse(value) ??
errorValue.value;
},
);