From 93f7ab9b7bd776fe0855844ea11f9a494dc44bb4 Mon Sep 17 00:00:00 2001 From: Damien Albisson Date: Mon, 17 Jun 2024 15:57:04 +0200 Subject: [PATCH] Use min/max and decimals attributes of current and voltage for bpc --- lib/widgets/userspace_widgets/ic_bpc.dart | 50 +++++++++++++++++++++-- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/lib/widgets/userspace_widgets/ic_bpc.dart b/lib/widgets/userspace_widgets/ic_bpc.dart index 1a007cf..123c00d 100644 --- a/lib/widgets/userspace_widgets/ic_bpc.dart +++ b/lib/widgets/userspace_widgets/ic_bpc.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:panduza_sandbox_flutter/utils/const.dart'; +import 'package:panduza_sandbox_flutter/utils/utils_functions.dart'; import 'templates.dart'; import '../../utils/utils_objects/interface_connection.dart'; @@ -21,12 +22,19 @@ class IcBpc extends StatefulWidget { } class _IcBpcState extends State { + bool? _enableValueReq; bool? _enableValueEff; + int _voltageDecimal = 3; + double _voltageMin = 0; + double _voltageMax = 1; double? _voltageValueReq; double? _voltageValueEff; + int _currentDecimal = 3; + double _currentMin = 0; + double _currentMax = 1; double? _currentValueReq; double? _currentValueEff; @@ -67,6 +75,21 @@ class _IcBpcState extends State { } _voltageValueReq ??= _voltageValueEff; } + + if (field.key == "min") { + _voltageMin = value_to_double(field.value); + } + if (field.key == "max") { + _voltageMax = value_to_double(field.value); + } + if (field.key == "decimals") { + switch (field.value.runtimeType) { + case int: + _voltageDecimal = field.value; + case double: + _voltageDecimal = (field.value as double).toInt(); + } + } break; case "current": @@ -79,7 +102,24 @@ class _IcBpcState extends State { } _currentValueReq ??= _currentValueEff; } + + if (field.key == "min") { + _currentMin = value_to_double(field.value); + } + if (field.key == "max") { + _currentMax = value_to_double(field.value); + } + if (field.key == "decimals") { + switch (field.value.runtimeType) { + case int: + _currentDecimal = field.value; + case double: + _currentDecimal = (field.value as double).toInt(); + } + } break; + + } } } @@ -232,7 +272,7 @@ class _IcBpcState extends State { children: [ cardHeadLine(widget._interfaceConnection), Text( - 'Voltage : ${double.parse(_voltageValueReq!.toStringAsFixed(2))}V', + 'Voltage : ${double.parse(_voltageValueReq!.toStringAsFixed(_voltageDecimal))}V', style: TextStyle( color: black ), @@ -244,9 +284,11 @@ class _IcBpcState extends State { _voltageValueReq = value; }); }, + min: _voltageMin, + max: _voltageMax ), Text( - 'Current : ${double.parse(_currentValueReq!.toStringAsFixed(2))}V', + 'Current : ${double.parse(_currentValueReq!.toStringAsFixed(_currentDecimal))}V', style: TextStyle( color: black ), @@ -258,8 +300,8 @@ class _IcBpcState extends State { _currentValueReq = value; }); }, - // min: 0.0, - // max: 100.0, + min: _currentMin, + max: _currentMax, ), Row( children: [