Gauge card optimizations

This commit is contained in:
Yegor Vialov
2020-04-14 18:39:21 +00:00
parent 0e92418a33
commit da5f663396

View File

@ -1,6 +1,6 @@
part of '../../main.dart'; part of '../../main.dart';
class GaugeCardBody extends StatefulWidget { class GaugeCardBody extends StatelessWidget {
final int min; final int min;
final int max; final int max;
@ -8,32 +8,26 @@ class GaugeCardBody extends StatefulWidget {
GaugeCardBody({Key key, this.min, this.max, this.severity}) : super(key: key); GaugeCardBody({Key key, this.min, this.max, this.severity}) : super(key: key);
@override
_GaugeCardBodyState createState() => _GaugeCardBodyState();
}
class _GaugeCardBodyState extends State<GaugeCardBody> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper; EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper;
double fixedValue; double fixedValue;
double value = entityWrapper.entity.doubleState; double value = entityWrapper.entity.doubleState;
if (value > widget.max) { if (value > max) {
fixedValue = widget.max.toDouble(); fixedValue = max.toDouble();
} else if (value < widget.min) { } else if (value < min) {
fixedValue = widget.min.toDouble(); fixedValue = min.toDouble();
} else { } else {
fixedValue = value; fixedValue = value;
} }
List<GaugeRange> ranges; List<GaugeRange> ranges;
Color currentColor; Color currentColor;
if (widget.severity != null && widget.severity["green"] is int && widget.severity["red"] is int && widget.severity["yellow"] is int) { if (severity != null && severity["green"] is int && severity["red"] is int && severity["yellow"] is int) {
List<RangeContainer> rangesList = <RangeContainer>[ List<RangeContainer> rangesList = <RangeContainer>[
RangeContainer(widget.severity["green"], HAClientTheme().getGreenGaugeColor()), RangeContainer(severity["green"], HAClientTheme().getGreenGaugeColor()),
RangeContainer(widget.severity["red"], HAClientTheme().getRedGaugeColor()), RangeContainer(severity["red"], HAClientTheme().getRedGaugeColor()),
RangeContainer(widget.severity["yellow"], HAClientTheme().getYellowGaugeColor()) RangeContainer(severity["yellow"], HAClientTheme().getYellowGaugeColor())
]; ];
rangesList.sort((current, next) { rangesList.sort((current, next) {
if (current.startFrom > next.startFrom) { if (current.startFrom > next.startFrom) {
@ -72,7 +66,7 @@ class _GaugeCardBodyState extends State<GaugeCardBody> {
), ),
GaugeRange( GaugeRange(
startValue: rangesList[2].startFrom.toDouble(), startValue: rangesList[2].startFrom.toDouble(),
endValue: widget.max.toDouble(), endValue: max.toDouble(),
color: rangesList[2].color.withOpacity(0.1), color: rangesList[2].color.withOpacity(0.1),
sizeUnit: GaugeSizeUnit.factor, sizeUnit: GaugeSizeUnit.factor,
endWidth: 0.3, endWidth: 0.3,
@ -84,8 +78,8 @@ class _GaugeCardBodyState extends State<GaugeCardBody> {
currentColor = Theme.of(context).primaryColorDark; currentColor = Theme.of(context).primaryColorDark;
ranges = <GaugeRange>[ ranges = <GaugeRange>[
GaugeRange( GaugeRange(
startValue: widget.min.toDouble(), startValue: min.toDouble(),
endValue: widget.max.toDouble(), endValue: max.toDouble(),
color: Theme.of(context).primaryColorDark.withOpacity(0.1), color: Theme.of(context).primaryColorDark.withOpacity(0.1),
sizeUnit: GaugeSizeUnit.factor, sizeUnit: GaugeSizeUnit.factor,
endWidth: 0.3, endWidth: 0.3,
@ -115,8 +109,8 @@ class _GaugeCardBodyState extends State<GaugeCardBody> {
return SfRadialGauge( return SfRadialGauge(
axes: <RadialAxis>[ axes: <RadialAxis>[
RadialAxis( RadialAxis(
maximum: widget.max.toDouble(), maximum: max.toDouble(),
minimum: widget.min.toDouble(), minimum: min.toDouble(),
showLabels: false, showLabels: false,
useRangeColorForAxis: true, useRangeColorForAxis: true,
showTicks: false, showTicks: false,
@ -172,6 +166,7 @@ class _GaugeCardBodyState extends State<GaugeCardBody> {
), ),
); );
} }
} }
class RangeContainer { class RangeContainer {