diff --git a/lib/cards/widgets/gauge_card_body.dart b/lib/cards/widgets/gauge_card_body.dart index 62ea8c9..3a59e82 100644 --- a/lib/cards/widgets/gauge_card_body.dart +++ b/lib/cards/widgets/gauge_card_body.dart @@ -28,6 +28,7 @@ class _GaugeCardBodyState extends State { } List ranges; + Color currentColor; if (widget.severity != null && widget.severity["green"] is int && widget.severity["red"] is int && widget.severity["yellow"] is int) { List rangesList = [ RangeContainer(widget.severity["green"], HAClientTheme().getGreenGaugeColor()), @@ -43,11 +44,20 @@ class _GaugeCardBodyState extends State { } return 0; }); + + if (fixedValue < rangesList[1].startFrom) { + currentColor = rangesList[0].color; + } else if (fixedValue < rangesList[2].startFrom && fixedValue >= rangesList[1].startFrom) { + currentColor = rangesList[1].color; + } else { + currentColor = rangesList[2].color; + } + ranges = [ GaugeRange( startValue: rangesList[0].startFrom.toDouble(), endValue: rangesList[1].startFrom.toDouble(), - color: fixedValue < rangesList[1].startFrom ? rangesList[0].color : rangesList[0].color.withOpacity(0.1), + color: rangesList[0].color.withOpacity(0.1), sizeUnit: GaugeSizeUnit.factor, endWidth: 0.3, startWidth: 0.3 @@ -55,7 +65,7 @@ class _GaugeCardBodyState extends State { GaugeRange( startValue: rangesList[1].startFrom.toDouble(), endValue: rangesList[2].startFrom.toDouble(), - color: (fixedValue < rangesList[2].startFrom && fixedValue >= rangesList[1].startFrom) ? rangesList[1].color : rangesList[1].color.withOpacity(0.1), + color: rangesList[1].color.withOpacity(0.1), sizeUnit: GaugeSizeUnit.factor, endWidth: 0.3, startWidth: 0.3 @@ -63,7 +73,7 @@ class _GaugeCardBodyState extends State { GaugeRange( startValue: rangesList[2].startFrom.toDouble(), endValue: widget.max.toDouble(), - color: fixedValue >= rangesList[2].startFrom ? rangesList[2].color : rangesList[2].color.withOpacity(0.1), + color: rangesList[2].color.withOpacity(0.1), sizeUnit: GaugeSizeUnit.factor, endWidth: 0.3, startWidth: 0.3 @@ -71,14 +81,15 @@ class _GaugeCardBodyState extends State { ]; } if (ranges == null) { + currentColor = Theme.of(context).primaryColorDark; ranges = [ GaugeRange( startValue: widget.min.toDouble(), endValue: widget.max.toDouble(), - color: Theme.of(context).primaryColorDark, + color: Theme.of(context).primaryColorDark.withOpacity(0.1), sizeUnit: GaugeSizeUnit.factor, endWidth: 0.3, - startWidth: 0.3 + startWidth: 0.3, ) ]; } @@ -107,9 +118,15 @@ class _GaugeCardBodyState extends State { maximum: widget.max.toDouble(), minimum: widget.min.toDouble(), showLabels: false, + useRangeColorForAxis: true, showTicks: false, canScaleToFit: true, ranges: ranges, + axisLineStyle: AxisLineStyle( + thickness: 0.3, + thicknessUnit: GaugeSizeUnit.factor, + color: Colors.transparent + ), annotations: [ GaugeAnnotation( angle: -90, @@ -135,27 +152,16 @@ class _GaugeCardBodyState extends State { ), ) ], - axisLineStyle: AxisLineStyle( - thickness: 0.3, - thicknessUnit: GaugeSizeUnit.factor - ), startAngle: 180, endAngle: 0, pointers: [ - NeedlePointer( + RangePointer( value: fixedValue, - lengthUnit: GaugeSizeUnit.factor, - needleLength: 0.9, - needleColor: Theme.of(context).accentColor, + sizeUnit: GaugeSizeUnit.factor, + width: 0.3, + color: currentColor, enableAnimation: true, - needleStartWidth: 1, animationType: AnimationType.bounceOut, - needleEndWidth: 3, - knobStyle: KnobStyle( - sizeUnit: GaugeSizeUnit.factor, - color: Theme.of(context).buttonColor, - knobRadius: 0.1 - ) ) ] )