2020-05-14 15:13:23 +03:00
|
|
|
part of '../main.dart';
|
|
|
|
|
2020-05-14 18:38:22 +03:00
|
|
|
class LightCard extends StatefulWidget {
|
2020-05-14 15:13:23 +03:00
|
|
|
|
|
|
|
final LightCardData card;
|
|
|
|
|
|
|
|
LightCard({Key key, this.card}) : super(key: key);
|
|
|
|
|
2020-05-14 18:38:22 +03:00
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
|
|
return _LightCardState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _LightCardState extends State<LightCard> {
|
|
|
|
|
|
|
|
double _actualBrightness;
|
2020-05-22 15:54:39 +03:00
|
|
|
double _newBrightness;
|
2020-05-14 18:38:22 +03:00
|
|
|
bool _changedHere = false;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _setBrightness(double value, LightEntity entity) {
|
|
|
|
setState((){
|
|
|
|
_newBrightness = value;
|
|
|
|
_changedHere = true;
|
|
|
|
});
|
|
|
|
ConnectionManager().callService(
|
|
|
|
domain: entity.domain,
|
|
|
|
service: "turn_on",
|
|
|
|
entityId: entity.entityId,
|
|
|
|
data: {"brightness": value.round()}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-05-14 15:13:23 +03:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-05-14 18:38:22 +03:00
|
|
|
EntityWrapper entityWrapper = widget.card.entity;
|
2020-05-14 15:13:23 +03:00
|
|
|
LightEntity entity = entityWrapper.entity;
|
|
|
|
if (entityWrapper.entity.statelessType == StatelessEntityType.missed) {
|
|
|
|
return EntityModel(
|
2020-05-14 18:38:22 +03:00
|
|
|
entityWrapper: widget.card.entity,
|
2020-05-14 15:13:23 +03:00
|
|
|
child: MissedEntityWidget(),
|
|
|
|
handleTap: false,
|
|
|
|
);
|
|
|
|
}
|
2020-05-14 18:38:22 +03:00
|
|
|
entityWrapper.overrideName = widget.card.name ??
|
2020-05-14 15:13:23 +03:00
|
|
|
entityWrapper.displayName;
|
2020-05-14 18:38:22 +03:00
|
|
|
entityWrapper.overrideIcon = widget.card.icon ??
|
2020-05-14 15:13:23 +03:00
|
|
|
entityWrapper.icon;
|
2020-05-22 15:54:39 +03:00
|
|
|
|
2020-05-14 18:38:22 +03:00
|
|
|
if (!_changedHere) {
|
2020-05-22 15:54:39 +03:00
|
|
|
_actualBrightness = (entity.brightness ?? 0).toDouble();
|
2020-05-14 18:38:22 +03:00
|
|
|
_newBrightness = _actualBrightness;
|
|
|
|
} else {
|
|
|
|
_changedHere = false;
|
|
|
|
}
|
|
|
|
Color lightColor = entity.color?.toColor();
|
|
|
|
Color color;
|
|
|
|
if (lightColor != null && lightColor != Colors.white) {
|
|
|
|
color = lightColor;
|
|
|
|
} else {
|
2020-05-22 15:54:39 +03:00
|
|
|
color = Theme.of(context).accentColor;
|
2020-05-14 18:38:22 +03:00
|
|
|
}
|
2020-05-22 15:54:39 +03:00
|
|
|
|
2020-05-14 15:13:23 +03:00
|
|
|
return CardWrapper(
|
|
|
|
padding: EdgeInsets.all(4),
|
|
|
|
child: EntityModel(
|
|
|
|
entityWrapper: entityWrapper,
|
2020-05-14 18:38:22 +03:00
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
ConstrainedBox(
|
|
|
|
constraints: BoxConstraints.loose(Size(200, 200)),
|
|
|
|
child: AspectRatio(
|
|
|
|
aspectRatio: 1,
|
|
|
|
child: Stack(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
SfRadialGauge(
|
|
|
|
axes: <RadialAxis>[
|
|
|
|
RadialAxis(
|
|
|
|
onAxisTapped: (val) {
|
|
|
|
_setBrightness(val, entity);
|
|
|
|
},
|
|
|
|
maximum: 255,
|
|
|
|
minimum: 0,
|
|
|
|
showLabels: false,
|
|
|
|
showTicks: false,
|
|
|
|
axisLineStyle: AxisLineStyle(
|
|
|
|
thickness: 0.05,
|
|
|
|
thicknessUnit: GaugeSizeUnit.factor,
|
|
|
|
color: HAClientTheme().getDisabledStateColor(context)
|
|
|
|
),
|
|
|
|
pointers: <GaugePointer>[
|
|
|
|
RangePointer(
|
|
|
|
value: _actualBrightness,
|
|
|
|
sizeUnit: GaugeSizeUnit.factor,
|
|
|
|
width: 0.05,
|
|
|
|
color: color,
|
|
|
|
enableAnimation: true,
|
|
|
|
animationType: AnimationType.bounceOut,
|
|
|
|
),
|
|
|
|
MarkerPointer(
|
|
|
|
value: _newBrightness,
|
|
|
|
markerType: MarkerType.circle,
|
|
|
|
markerHeight: 20,
|
|
|
|
markerWidth: 20,
|
|
|
|
enableDragging: true,
|
|
|
|
onValueChangeEnd: (val) {
|
|
|
|
_setBrightness(val, entity);
|
|
|
|
},
|
|
|
|
color: HAClientTheme().getColorByEntityState(entity.state, context)
|
|
|
|
//enableAnimation: true,
|
|
|
|
//animationType: AnimationType.bounceOut,
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
],
|
2020-05-14 15:13:23 +03:00
|
|
|
),
|
2020-05-14 18:38:22 +03:00
|
|
|
FractionallySizedBox(
|
|
|
|
heightFactor: 0.4,
|
|
|
|
widthFactor: 0.4,
|
|
|
|
child: AspectRatio(
|
|
|
|
aspectRatio: 1,
|
|
|
|
child: InkResponse(
|
|
|
|
onTap: () => entityWrapper.handleTap(),
|
|
|
|
onLongPress: () => entityWrapper.handleHold(),
|
|
|
|
child: FittedBox(
|
|
|
|
fit: BoxFit.contain,
|
|
|
|
child: EntityIcon(
|
|
|
|
showBadge: false,
|
|
|
|
padding: EdgeInsets.all(0)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2020-05-14 15:13:23 +03:00
|
|
|
)
|
2020-05-14 18:38:22 +03:00
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
EntityName(
|
|
|
|
padding: EdgeInsets.all(0),
|
|
|
|
wordsWrap: true,
|
|
|
|
maxLines: 3,
|
|
|
|
textOverflow: TextOverflow.ellipsis,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
)
|
|
|
|
],
|
2020-05-14 15:13:23 +03:00
|
|
|
),
|
|
|
|
handleTap: true
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2020-05-14 18:38:22 +03:00
|
|
|
}
|
|
|
|
|