updateValue method
void
updateValue()
Implementation
void updateValue() {
num? value;
if (controller.text.isNotEmpty) {
value = num.tryParse(controller.text);
if (value == null && widget.allowExpressions) {
try {
value = Parser()
.parse(controller.text)
.evaluate(EvaluationType.REAL, ContextModel());
// If the value is infinite or not a number, we reset the value with
// the previous valid value. For example, if the user tap 1024^200
// (the result is too big), the condition value.isInfinite is true.
if (value!.isInfinite || value.isNaN) {
value = previousValidValue;
}
} catch (_) {
value = previousValidValue;
}
} else {
value ??= previousValidValue;
}
if (value != null && widget.max != null && value > widget.max!) {
value = widget.max;
} else if (value != null && widget.min != null && value < widget.min!) {
value = widget.min;
}
if (T == int) {
value = value?.toInt();
} else {
value = value?.toDouble();
}
controller.text = _format(value) ?? '';
}
previousValidValue = value;
if (widget.onChanged != null) {
widget.onChanged!(value as T?);
}
}