From 2085bd65e2ae90bfc7b53a2a009c7108343e1bd5 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 16 Jul 2024 17:17:05 +0200 Subject: [PATCH] Fix widget powermeter and thermometer display with the good decimal number --- lib/utils/utils_functions.dart | 8 ++++++-- lib/widgets/userspace_widgets/ic_blc.dart | 4 ++-- lib/widgets/userspace_widgets/ic_bpc.dart | 4 ++-- lib/widgets/userspace_widgets/ic_powermeter.dart | 3 ++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/utils/utils_functions.dart b/lib/utils/utils_functions.dart index fabf54a..2a486d5 100644 --- a/lib/utils/utils_functions.dart +++ b/lib/utils/utils_functions.dart @@ -299,7 +299,8 @@ double valueToDouble(dynamic value) { // Show W, mW or micro W in function of value, // if 0.001 W show 1 mW -String formatValueInBaseMilliMicro(double value, String prefix, String suffix) { +// decimalNumbers is the number after the decimal point show +String formatValueInBaseMilliMicro(double value, String prefix, String suffix, int decimalNumbers) { String newSuffix = suffix; double newValue = value; @@ -317,7 +318,10 @@ String formatValueInBaseMilliMicro(double value, String prefix, String suffix) { if (newValue == 0.0 ) { newSuffix = suffix; } - return "$prefix$newValue $newSuffix"; + + // Problem in precision float value ask to do again a rounding + String newValueString = newValue.toStringAsFixed(decimalNumbers); + return "$prefix$newValueString $newSuffix"; } // typeAttribute example : "power" diff --git a/lib/widgets/userspace_widgets/ic_blc.dart b/lib/widgets/userspace_widgets/ic_blc.dart index ba229b2..6078e5d 100644 --- a/lib/widgets/userspace_widgets/ic_blc.dart +++ b/lib/widgets/userspace_widgets/ic_blc.dart @@ -393,7 +393,7 @@ class _IcBlcState extends State { partOfWidget.add( Text( - 'Power : ${double.parse(_powerPercentageReq!.toStringAsFixed(_powerDecimals))}% (${formatValueInBaseMilliMicro(double.parse(_powerValueReq!.toStringAsFixed(_powerDecimals)), "", "W")})', + 'Power : ${double.parse(_powerPercentageReq!.toStringAsFixed(_powerDecimals))}% (${formatValueInBaseMilliMicro(double.parse(_powerValueReq!.toStringAsFixed(_powerDecimals)), "", "W", _powerDecimals)})', style: TextStyle( color: black ), @@ -438,7 +438,7 @@ class _IcBlcState extends State { partOfWidget.add( Text( - formatValueInBaseMilliMicro(double.parse(_currentValueReq!.toStringAsFixed(_currentDecimals)), "Current : ", "A"), + formatValueInBaseMilliMicro(double.parse(_currentValueReq!.toStringAsFixed(_currentDecimals)), "Current : ", "A", _currentDecimals), style: TextStyle( color: black ), diff --git a/lib/widgets/userspace_widgets/ic_bpc.dart b/lib/widgets/userspace_widgets/ic_bpc.dart index 8ea5587..3ea70c2 100644 --- a/lib/widgets/userspace_widgets/ic_bpc.dart +++ b/lib/widgets/userspace_widgets/ic_bpc.dart @@ -306,7 +306,7 @@ class _IcBpcState extends State { if (_voltageValueEff != null) { partOfWidget.add( Text( - formatValueInBaseMilliMicro(double.parse(_voltageValueReq!.toStringAsFixed(_voltageDecimal)), 'Voltage : ', 'V'), + formatValueInBaseMilliMicro(double.parse(_voltageValueReq!.toStringAsFixed(_voltageDecimal)), 'Voltage : ', 'V', _voltageDecimal), style: TextStyle( color: black ), @@ -332,7 +332,7 @@ class _IcBpcState extends State { if (_currentValueEff != null) { partOfWidget.add( Text( - formatValueInBaseMilliMicro(double.parse(_currentValueReq!.toStringAsFixed(_voltageDecimal)), 'Current : ', 'A'), + formatValueInBaseMilliMicro(double.parse(_currentValueReq!.toStringAsFixed(_voltageDecimal)), 'Current : ', 'A', _currentDecimal), style: TextStyle( color: black ), diff --git a/lib/widgets/userspace_widgets/ic_powermeter.dart b/lib/widgets/userspace_widgets/ic_powermeter.dart index 6fc3cb8..09c23cd 100644 --- a/lib/widgets/userspace_widgets/ic_powermeter.dart +++ b/lib/widgets/userspace_widgets/ic_powermeter.dart @@ -121,13 +121,14 @@ class _IcPowermeterState extends State { /// @override Widget build(BuildContext context) { + return Card( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ cardHeadLine(widget._interfaceConnection), Text( - formatValueInBaseMilliMicro(double.parse(_value.toStringAsFixed(_measureDecimal)), "", "W"), + formatValueInBaseMilliMicro(double.parse(_value.toStringAsFixed(_measureDecimal)), "", "W", _measureDecimal), style: TextStyle( color: black ),