mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
@ -125,7 +125,48 @@ class PowerClampPhasesDataWidget extends StatelessWidget {
|
|||||||
(e) => e.code == code,
|
(e) => e.code == code,
|
||||||
orElse: () => DataPoint(value: '--'),
|
orElse: () => DataPoint(value: '--'),
|
||||||
);
|
);
|
||||||
|
final value = element?.value;
|
||||||
|
if (code.contains('Current')) {
|
||||||
|
return _formatCurrentValue(value?.toString());
|
||||||
|
}
|
||||||
|
if (code.contains('PowerFactor')) {
|
||||||
|
return _formatPowerFactor(value?.toString());
|
||||||
|
}
|
||||||
|
if (code.contains('Voltage')) {
|
||||||
|
return _formatVoltage(value?.toString());
|
||||||
|
}
|
||||||
|
return value?.toString() ?? '--';
|
||||||
|
}
|
||||||
|
|
||||||
return element?.value.toString() ?? '--';
|
String _formatCurrentValue(String? value) {
|
||||||
|
if (value == null) return '--';
|
||||||
|
String str = value;
|
||||||
|
if (str.isEmpty || str == '--') return '--';
|
||||||
|
str = str.replaceAll(RegExp(r'[^0-9]'), '');
|
||||||
|
if (str.isEmpty) return '--';
|
||||||
|
if (str.length == 1) return '${str[0]}.0';
|
||||||
|
return '${str[0]}.${str.substring(1)}';
|
||||||
|
}
|
||||||
|
|
||||||
|
String _formatPowerFactor(String? value) {
|
||||||
|
if (value == null) return '--';
|
||||||
|
String str = value;
|
||||||
|
if (str.isEmpty || str == '--') return '--';
|
||||||
|
str = str.replaceAll(RegExp(r'[^0-9]'), '');
|
||||||
|
if (str.isEmpty) return '--';
|
||||||
|
final intValue = int.tryParse(str);
|
||||||
|
if (intValue == null) return '--';
|
||||||
|
final doubleValue = intValue / 100;
|
||||||
|
return doubleValue.toStringAsFixed(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
String _formatVoltage(String? value) {
|
||||||
|
if (value == null) return '--';
|
||||||
|
String str = value;
|
||||||
|
if (str.isEmpty || str == '--') return '--';
|
||||||
|
str = str.replaceAll(RegExp(r'[^0-9]'), '');
|
||||||
|
if (str.isEmpty) return '--';
|
||||||
|
if (str.length == 1) return '0.${str[0]}';
|
||||||
|
return '${str.substring(0, str.length - 1)}.${str.substring(str.length - 1)}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user