error en conversor de temperaturas
This commit is contained in:
parent
0c4fef93c1
commit
a48182ffbf
3 changed files with 10 additions and 10 deletions
|
|
@ -61,6 +61,7 @@ class _FormulaScreenState extends State<FormulaScreen> {
|
||||||
String? _result;
|
String? _result;
|
||||||
String? _selectedOutputUnit;
|
String? _selectedOutputUnit;
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
@ -106,15 +107,13 @@ class _FormulaScreenState extends State<FormulaScreen> {
|
||||||
final result = evaluator.evaluate(widget.formula, inputValues);
|
final result = evaluator.evaluate(widget.formula, inputValues);
|
||||||
|
|
||||||
// Convert output to selected unit if needed
|
// Convert output to selected unit if needed
|
||||||
if (_selectedOutputUnit != widget.formula.output.unit) {
|
_result = widget.corpus.convert(
|
||||||
_result = widget.corpus.convert(
|
result,
|
||||||
result,
|
widget.formula.output.unit,
|
||||||
widget.formula.output.unit,
|
_selectedOutputUnit!,
|
||||||
_selectedOutputUnit!,
|
).toStringAsFixed(2);
|
||||||
).toStringAsFixed(2);
|
|
||||||
} else {
|
//print( "_evaluateFormula: result:${result} _result:${_result}");
|
||||||
_result = result.toStringAsFixed(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
setState(() {});
|
setState(() {});
|
||||||
} catch (e, stack) {
|
} catch (e, stack) {
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,7 @@ class Corpus{
|
||||||
final xBase = _convertToBase(x, fromUnit);
|
final xBase = _convertToBase(x, fromUnit);
|
||||||
final xTo = _convertFromBase(xBase, toUnit);
|
final xTo = _convertFromBase(xBase, toUnit);
|
||||||
|
|
||||||
|
//print( "convert: x:${x}${fromUnit} xTo:${xTo}${toUnit}");
|
||||||
return xTo;
|
return xTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
"name": "Temperature converter",
|
"name": "Temperature converter",
|
||||||
"description": "Example of simple formula, just unit conversion",
|
"description": "Example of simple formula, just unit conversion",
|
||||||
"input": [
|
"input": [
|
||||||
{"name": "Input", "unit": "Celsius" }
|
{"name": "Input", "unit": "Kelvin" }
|
||||||
],
|
],
|
||||||
"output": {"name": "Output", "unit": "Kelvin" },
|
"output": {"name": "Output", "unit": "Kelvin" },
|
||||||
"d4rtCode": "Output = Input;",
|
"d4rtCode": "Output = Input;",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue