Skip to content
This repository has been archived by the owner on Dec 28, 2024. It is now read-only.

Commit

Permalink
Fix widget powermeter and thermometer display with the good decimal n…
Browse files Browse the repository at this point in the history
…umber
  • Loading branch information
Darcraytore1 committed Jul 16, 2024
1 parent f73e7c7 commit 2085bd6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
8 changes: 6 additions & 2 deletions lib/utils/utils_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions lib/widgets/userspace_widgets/ic_blc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ class _IcBlcState extends State<IcBlc> {

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
),
Expand Down Expand Up @@ -438,7 +438,7 @@ class _IcBlcState extends State<IcBlc> {

partOfWidget.add(
Text(
formatValueInBaseMilliMicro(double.parse(_currentValueReq!.toStringAsFixed(_currentDecimals)), "Current : ", "A"),
formatValueInBaseMilliMicro(double.parse(_currentValueReq!.toStringAsFixed(_currentDecimals)), "Current : ", "A", _currentDecimals),
style: TextStyle(
color: black
),
Expand Down
4 changes: 2 additions & 2 deletions lib/widgets/userspace_widgets/ic_bpc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class _IcBpcState extends State<IcBpc> {
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
),
Expand All @@ -332,7 +332,7 @@ class _IcBpcState extends State<IcBpc> {
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
),
Expand Down
3 changes: 2 additions & 1 deletion lib/widgets/userspace_widgets/ic_powermeter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,14 @@ class _IcPowermeterState extends State<IcPowermeter> {
///
@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
),
Expand Down

0 comments on commit 2085bd6

Please sign in to comment.