This commit is contained in:
Yegor Vialov 2020-05-14 15:38:22 +00:00
parent 78d6b38b92
commit e4d1a4f823
4 changed files with 136 additions and 61 deletions

View File

@ -380,7 +380,7 @@ class LightCardData extends CardData {
entity: HomeAssistant().entities.get(entitiId), entity: HomeAssistant().entities.get(entitiId),
overrideName: name, overrideName: name,
overrideIcon: icon, overrideIcon: icon,
uiAction: EntityUIAction() uiAction: EntityUIAction()..tapAction = EntityUIAction.toggle
)); ));
} else { } else {
entities.add(EntityWrapper(entity: Entity.missed(entitiId))); entities.add(EntityWrapper(entity: Entity.missed(entitiId)));

View File

@ -1,85 +1,159 @@
part of '../main.dart'; part of '../main.dart';
class LightCard extends StatelessWidget { class LightCard extends StatefulWidget {
final LightCardData card; final LightCardData card;
LightCard({Key key, this.card}) : super(key: key); 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
EntityWrapper entityWrapper = card.entity; EntityWrapper entityWrapper = widget.card.entity;
LightEntity entity = entityWrapper.entity; LightEntity entity = entityWrapper.entity;
if (entityWrapper.entity.statelessType == StatelessEntityType.missed) { if (entityWrapper.entity.statelessType == StatelessEntityType.missed) {
return EntityModel( return EntityModel(
entityWrapper: card.entity, entityWrapper: widget.card.entity,
child: MissedEntityWidget(), child: MissedEntityWidget(),
handleTap: false, handleTap: false,
); );
} }
entityWrapper.overrideName = card.name ?? entityWrapper.overrideName = widget.card.name ??
entityWrapper.displayName; entityWrapper.displayName;
entityWrapper.overrideIcon = card.icon ?? entityWrapper.overrideIcon = widget.card.icon ??
entityWrapper.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( return CardWrapper(
padding: EdgeInsets.all(4), padding: EdgeInsets.all(4),
child: EntityModel( child: EntityModel(
entityWrapper: entityWrapper, entityWrapper: entityWrapper,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
ConstrainedBox(
constraints: BoxConstraints.loose(Size(200, 200)),
child: AspectRatio( child: AspectRatio(
aspectRatio: 1.8, aspectRatio: 1,
child: Stack( child: Stack(
alignment: Alignment.center, alignment: Alignment.center,
children: <Widget>[ children: <Widget>[
SfRadialGauge( SfRadialGauge(
axes: <RadialAxis>[ axes: <RadialAxis>[
RadialAxis( RadialAxis(
onAxisTapped: (val) {
_setBrightness(val, entity);
},
maximum: 255, maximum: 255,
minimum: 0, minimum: 0,
showLabels: false, showLabels: false,
showTicks: false, showTicks: false,
canScaleToFit: true,
axisLineStyle: AxisLineStyle( axisLineStyle: AxisLineStyle(
thickness: 0.05, thickness: 0.05,
thicknessUnit: GaugeSizeUnit.factor, thicknessUnit: GaugeSizeUnit.factor,
color: HAClientTheme().getDisabledStateColor(context) color: HAClientTheme().getDisabledStateColor(context)
), ),
pointers: <GaugePointer>[ pointers: <GaugePointer>[
/*RangePointer( RangePointer(
value: value, value: _actualBrightness,
sizeUnit: GaugeSizeUnit.factor, sizeUnit: GaugeSizeUnit.factor,
width: 0.05, width: 0.05,
color: HAClientTheme().getOnStateColor(context), color: color,
enableAnimation: true, enableAnimation: true,
animationType: AnimationType.bounceOut, animationType: AnimationType.bounceOut,
),*/ ),
MarkerPointer( MarkerPointer(
value: value, value: _newBrightness,
markerType: MarkerType.circle, markerType: MarkerType.circle,
markerHeight: 20, markerHeight: 20,
markerWidth: 20, markerWidth: 20,
enableDragging: true, enableDragging: true,
onValueChangeStart: (_) { onValueChangeEnd: (val) {
Logger.d('Value change start'); _setBrightness(val, entity);
}, },
onValueChanging: (args) { color: HAClientTheme().getColorByEntityState(entity.state, context)
Logger.d('Value changing: ${args.value}'); //enableAnimation: true,
}, //animationType: AnimationType.bounceOut,
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 handleTap: true
) )
); );
} }
} }

View File

@ -7,8 +7,9 @@ class EntityIcon extends StatelessWidget {
final EdgeInsetsGeometry imagePadding; final EdgeInsetsGeometry imagePadding;
final double size; final double size;
final Color color; 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) { int getDefaultIconByEntityId(String entityId, String deviceClass, String state) {
if (entityId == null) { if (entityId == null) {
@ -71,7 +72,7 @@ class EntityIcon extends StatelessWidget {
iconCode = getDefaultIconByEntityId(entityWrapper.entity.entityId, iconCode = getDefaultIconByEntityId(entityWrapper.entity.entityId,
entityWrapper.entity.deviceClass, entityWrapper.entity.state); // 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).supportColor &&
(entityWrapper.entity as LightEntity).color != null && (entityWrapper.entity as LightEntity).color != null &&
(entityWrapper.entity as LightEntity).color.toColor() != Colors.white (entityWrapper.entity as LightEntity).color.toColor() != Colors.white

View File

@ -31,8 +31,8 @@ dependencies:
workmanager: ^0.2.2 workmanager: ^0.2.2
battery: ^1.0.0 battery: ^1.0.0
firebase_crashlytics: ^0.1.3+3 firebase_crashlytics: ^0.1.3+3
syncfusion_flutter_core: ^18.1.48 syncfusion_flutter_core: ^18.1.52
syncfusion_flutter_gauges: ^18.1.48 syncfusion_flutter_gauges: ^18.1.52
dev_dependencies: dev_dependencies: