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

Fix widget powermeter and thermometer display with the good decimal n… #108

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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