Resolves #212
This commit is contained in:
parent
78d6b38b92
commit
e4d1a4f823
@ -380,7 +380,7 @@ class LightCardData extends CardData {
|
||||
entity: HomeAssistant().entities.get(entitiId),
|
||||
overrideName: name,
|
||||
overrideIcon: icon,
|
||||
uiAction: EntityUIAction()
|
||||
uiAction: EntityUIAction()..tapAction = EntityUIAction.toggle
|
||||
));
|
||||
} else {
|
||||
entities.add(EntityWrapper(entity: Entity.missed(entitiId)));
|
||||
|
@ -1,85 +1,159 @@
|
||||
part of '../main.dart';
|
||||
|
||||
class LightCard extends StatelessWidget {
|
||||
class LightCard extends StatefulWidget {
|
||||
|
||||
final LightCardData card;
|
||||
|
||||
LightCard({Key key, this.card}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _LightCardState();
|
||||
}
|
||||
}
|
||||
|
||||
class _LightCardState extends State<LightCard> {
|
||||
|
||||
double _newBrightness;
|
||||
double _actualBrightness;
|
||||
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()}
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
EntityWrapper entityWrapper = card.entity;
|
||||
EntityWrapper entityWrapper = widget.card.entity;
|
||||
LightEntity entity = entityWrapper.entity;
|
||||
if (entityWrapper.entity.statelessType == StatelessEntityType.missed) {
|
||||
return EntityModel(
|
||||
entityWrapper: card.entity,
|
||||
entityWrapper: widget.card.entity,
|
||||
child: MissedEntityWidget(),
|
||||
handleTap: false,
|
||||
);
|
||||
}
|
||||
entityWrapper.overrideName = card.name ??
|
||||
entityWrapper.overrideName = widget.card.name ??
|
||||
entityWrapper.displayName;
|
||||
entityWrapper.overrideIcon = card.icon ??
|
||||
entityWrapper.overrideIcon = widget.card.icon ??
|
||||
entityWrapper.icon;
|
||||
double value = (entity.brightness ?? 0).toDouble();
|
||||
|
||||
_actualBrightness = (entity.brightness ?? 0).toDouble();
|
||||
if (!_changedHere) {
|
||||
_newBrightness = _actualBrightness;
|
||||
} else {
|
||||
_changedHere = false;
|
||||
}
|
||||
Color lightColor = entity.color?.toColor();
|
||||
Color color;
|
||||
if (lightColor != null && lightColor != Colors.white) {
|
||||
color = lightColor;
|
||||
} else {
|
||||
color = HAClientTheme().getOnStateColor(context);
|
||||
}
|
||||
return CardWrapper(
|
||||
padding: EdgeInsets.all(4),
|
||||
child: EntityModel(
|
||||
entityWrapper: entityWrapper,
|
||||
child: AspectRatio(
|
||||
aspectRatio: 1.8,
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: <Widget>[
|
||||
SfRadialGauge(
|
||||
axes: <RadialAxis>[
|
||||
RadialAxis(
|
||||
maximum: 255,
|
||||
minimum: 0,
|
||||
showLabels: false,
|
||||
showTicks: false,
|
||||
canScaleToFit: true,
|
||||
axisLineStyle: AxisLineStyle(
|
||||
thickness: 0.05,
|
||||
thicknessUnit: GaugeSizeUnit.factor,
|
||||
color: HAClientTheme().getDisabledStateColor(context)
|
||||
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,
|
||||
)
|
||||
]
|
||||
)
|
||||
],
|
||||
),
|
||||
pointers: <GaugePointer>[
|
||||
/*RangePointer(
|
||||
value: value,
|
||||
sizeUnit: GaugeSizeUnit.factor,
|
||||
width: 0.05,
|
||||
color: HAClientTheme().getOnStateColor(context),
|
||||
enableAnimation: true,
|
||||
animationType: AnimationType.bounceOut,
|
||||
),*/
|
||||
MarkerPointer(
|
||||
value: value,
|
||||
markerType: MarkerType.circle,
|
||||
markerHeight: 20,
|
||||
markerWidth: 20,
|
||||
enableDragging: true,
|
||||
onValueChangeStart: (_) {
|
||||
Logger.d('Value change start');
|
||||
},
|
||||
onValueChanging: (args) {
|
||||
Logger.d('Value changing: ${args.value}');
|
||||
},
|
||||
color: HAClientTheme().getOnStateColor(context),
|
||||
enableAnimation: true,
|
||||
animationType: AnimationType.bounceOut,
|
||||
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)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
]
|
||||
)
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
)
|
||||
],
|
||||
)
|
||||
)
|
||||
),
|
||||
EntityName(
|
||||
padding: EdgeInsets.all(0),
|
||||
wordsWrap: true,
|
||||
maxLines: 3,
|
||||
textOverflow: TextOverflow.ellipsis,
|
||||
textAlign: TextAlign.center,
|
||||
)
|
||||
],
|
||||
),
|
||||
handleTap: true
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,9 @@ class EntityIcon extends StatelessWidget {
|
||||
final EdgeInsetsGeometry imagePadding;
|
||||
final double size;
|
||||
final Color color;
|
||||
final bool showBadge;
|
||||
|
||||
const EntityIcon({Key key, this.color, this.size: Sizes.iconSize, this.padding: const EdgeInsets.all(0.0), this.iconPadding, this.imagePadding}) : super(key: key);
|
||||
const EntityIcon({Key key, this.color, this.showBadge: true, this.size: Sizes.iconSize, this.padding: const EdgeInsets.all(0.0), this.iconPadding, this.imagePadding}) : super(key: key);
|
||||
|
||||
int getDefaultIconByEntityId(String entityId, String deviceClass, String state) {
|
||||
if (entityId == null) {
|
||||
@ -71,7 +72,7 @@ class EntityIcon extends StatelessWidget {
|
||||
iconCode = getDefaultIconByEntityId(entityWrapper.entity.entityId,
|
||||
entityWrapper.entity.deviceClass, entityWrapper.entity.state); //
|
||||
}
|
||||
if (entityWrapper.entity is LightEntity &&
|
||||
if (showBadge && entityWrapper.entity is LightEntity &&
|
||||
(entityWrapper.entity as LightEntity).supportColor &&
|
||||
(entityWrapper.entity as LightEntity).color != null &&
|
||||
(entityWrapper.entity as LightEntity).color.toColor() != Colors.white
|
||||
|
@ -31,8 +31,8 @@ dependencies:
|
||||
workmanager: ^0.2.2
|
||||
battery: ^1.0.0
|
||||
firebase_crashlytics: ^0.1.3+3
|
||||
syncfusion_flutter_core: ^18.1.48
|
||||
syncfusion_flutter_gauges: ^18.1.48
|
||||
syncfusion_flutter_core: ^18.1.52
|
||||
syncfusion_flutter_gauges: ^18.1.52
|
||||
|
||||
|
||||
dev_dependencies:
|
||||
|
Reference in New Issue
Block a user