2020-04-25 18:59:07 +03:00
|
|
|
part of '../main.dart';
|
|
|
|
|
|
|
|
class GaugeCard extends StatelessWidget {
|
|
|
|
|
2020-04-27 01:46:37 +03:00
|
|
|
final GaugeCardData card;
|
2020-04-25 18:59:07 +03:00
|
|
|
|
|
|
|
GaugeCard({Key key, this.card}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-04-27 01:46:37 +03:00
|
|
|
EntityWrapper entityWrapper = card.entity;
|
|
|
|
if (entityWrapper.entity.statelessType == StatelessEntityType.missed) {
|
|
|
|
return EntityModel(
|
|
|
|
entityWrapper: card.entity,
|
|
|
|
child: MissedEntityWidget(),
|
|
|
|
handleTap: false,
|
|
|
|
);
|
|
|
|
}
|
2020-04-25 18:59:07 +03:00
|
|
|
entityWrapper.overrideName = card.name ??
|
|
|
|
entityWrapper.displayName;
|
|
|
|
entityWrapper.unitOfMeasurementOverride = card.unit ??
|
|
|
|
entityWrapper.unitOfMeasurement;
|
|
|
|
double fixedValue;
|
|
|
|
double value = entityWrapper.entity.doubleState;
|
|
|
|
if (value > card.max) {
|
|
|
|
fixedValue = card.max.toDouble();
|
|
|
|
} else if (value < card.min) {
|
|
|
|
fixedValue = card.min.toDouble();
|
|
|
|
} else {
|
|
|
|
fixedValue = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<GaugeRange> ranges;
|
|
|
|
Color currentColor;
|
|
|
|
if (card.severity != null && card.severity["green"] is int && card.severity["red"] is int && card.severity["yellow"] is int) {
|
|
|
|
List<RangeContainer> rangesList = <RangeContainer>[
|
|
|
|
RangeContainer(card.severity["green"], HAClientTheme().getGreenGaugeColor()),
|
|
|
|
RangeContainer(card.severity["red"], HAClientTheme().getRedGaugeColor()),
|
|
|
|
RangeContainer(card.severity["yellow"], HAClientTheme().getYellowGaugeColor())
|
|
|
|
];
|
|
|
|
rangesList.sort((current, next) {
|
|
|
|
if (current.startFrom > next.startFrom) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (current.startFrom < next.startFrom) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
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: rangesList[0].color.withOpacity(0.1),
|
|
|
|
sizeUnit: GaugeSizeUnit.factor,
|
|
|
|
endWidth: 0.3,
|
|
|
|
startWidth: 0.3
|
|
|
|
),
|
|
|
|
GaugeRange(
|
|
|
|
startValue: rangesList[1].startFrom.toDouble(),
|
|
|
|
endValue: rangesList[2].startFrom.toDouble(),
|
|
|
|
color: rangesList[1].color.withOpacity(0.1),
|
|
|
|
sizeUnit: GaugeSizeUnit.factor,
|
|
|
|
endWidth: 0.3,
|
|
|
|
startWidth: 0.3
|
|
|
|
),
|
|
|
|
GaugeRange(
|
|
|
|
startValue: rangesList[2].startFrom.toDouble(),
|
|
|
|
endValue: card.max.toDouble(),
|
|
|
|
color: rangesList[2].color.withOpacity(0.1),
|
|
|
|
sizeUnit: GaugeSizeUnit.factor,
|
|
|
|
endWidth: 0.3,
|
|
|
|
startWidth: 0.3
|
|
|
|
)
|
|
|
|
];
|
|
|
|
}
|
|
|
|
if (ranges == null) {
|
|
|
|
currentColor = Theme.of(context).primaryColorDark;
|
|
|
|
ranges = <GaugeRange>[
|
|
|
|
GaugeRange(
|
|
|
|
startValue: card.min.toDouble(),
|
|
|
|
endValue: card.max.toDouble(),
|
|
|
|
color: Theme.of(context).primaryColorDark.withOpacity(0.1),
|
|
|
|
sizeUnit: GaugeSizeUnit.factor,
|
|
|
|
endWidth: 0.3,
|
|
|
|
startWidth: 0.3,
|
|
|
|
)
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return CardWrapper(
|
2020-04-27 23:56:33 +03:00
|
|
|
padding: EdgeInsets.all(4),
|
2020-04-25 18:59:07 +03:00
|
|
|
child: EntityModel(
|
|
|
|
entityWrapper: entityWrapper,
|
|
|
|
child: InkWell(
|
|
|
|
onTap: () => entityWrapper.handleTap(),
|
|
|
|
onLongPress: () => entityWrapper.handleHold(),
|
|
|
|
onDoubleTap: () => entityWrapper.handleDoubleTap(),
|
|
|
|
child: AspectRatio(
|
2020-04-27 23:56:33 +03:00
|
|
|
aspectRatio: 1.8,
|
|
|
|
child: Stack(
|
2020-04-28 23:36:11 +03:00
|
|
|
alignment: Alignment.bottomCenter,
|
2020-04-27 23:56:33 +03:00
|
|
|
children: <Widget>[
|
2020-04-29 20:48:15 +03:00
|
|
|
IgnorePointer(
|
|
|
|
ignoring: true,
|
|
|
|
child: SfRadialGauge(
|
|
|
|
axes: <RadialAxis>[
|
|
|
|
RadialAxis(
|
|
|
|
maximum: card.max.toDouble(),
|
|
|
|
minimum: card.min.toDouble(),
|
|
|
|
showLabels: false,
|
|
|
|
useRangeColorForAxis: true,
|
|
|
|
showTicks: false,
|
|
|
|
canScaleToFit: true,
|
|
|
|
ranges: ranges,
|
|
|
|
axisLineStyle: AxisLineStyle(
|
|
|
|
thickness: 0.3,
|
|
|
|
thicknessUnit: GaugeSizeUnit.factor,
|
|
|
|
color: Colors.transparent
|
|
|
|
),
|
|
|
|
startAngle: 180,
|
|
|
|
endAngle: 0,
|
|
|
|
pointers: <GaugePointer>[
|
|
|
|
RangePointer(
|
|
|
|
value: fixedValue,
|
|
|
|
sizeUnit: GaugeSizeUnit.factor,
|
|
|
|
width: 0.3,
|
|
|
|
color: currentColor,
|
|
|
|
enableAnimation: true,
|
|
|
|
animationType: AnimationType.bounceOut,
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
2020-04-27 23:56:33 +03:00
|
|
|
),
|
2020-04-28 23:36:11 +03:00
|
|
|
Column(
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
Flexible(
|
|
|
|
flex: 8,
|
|
|
|
fit: FlexFit.tight,
|
|
|
|
child: Container()
|
2020-04-27 23:56:33 +03:00
|
|
|
),
|
2020-04-28 23:36:11 +03:00
|
|
|
Flexible(
|
|
|
|
flex: 6,
|
|
|
|
fit: FlexFit.tight,
|
|
|
|
child: FractionallySizedBox(
|
|
|
|
widthFactor: 0.4,
|
|
|
|
child: FittedBox(
|
|
|
|
fit: BoxFit.contain,
|
|
|
|
alignment: Alignment.bottomCenter,
|
|
|
|
child: SimpleEntityState(
|
|
|
|
padding: EdgeInsets.all(0),
|
|
|
|
expanded: false,
|
|
|
|
maxLines: 1,
|
|
|
|
textAlign: TextAlign.center
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
2020-04-27 23:56:33 +03:00
|
|
|
),
|
2020-04-28 23:36:11 +03:00
|
|
|
Flexible(
|
|
|
|
flex: 3,
|
|
|
|
fit: FlexFit.tight,
|
|
|
|
child: FittedBox(
|
|
|
|
fit: BoxFit.contain,
|
|
|
|
child: EntityName(
|
|
|
|
padding: EdgeInsets.all(0),
|
|
|
|
textStyle: Theme.of(context).textTheme.subhead
|
|
|
|
),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
2020-04-25 18:59:07 +03:00
|
|
|
],
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
handleTap: true
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class RangeContainer {
|
|
|
|
final int startFrom;
|
|
|
|
Color color;
|
|
|
|
|
|
|
|
RangeContainer(this.startFrom, this.color);
|
|
|
|
}
|