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: AspectRatio( child: Column(
aspectRatio: 1.8, mainAxisSize: MainAxisSize.min,
child: Stack( crossAxisAlignment: CrossAxisAlignment.center,
alignment: Alignment.center, children: <Widget>[
children: <Widget>[ ConstrainedBox(
SfRadialGauge( constraints: BoxConstraints.loose(Size(200, 200)),
axes: <RadialAxis>[ child: AspectRatio(
RadialAxis( aspectRatio: 1,
maximum: 255, child: Stack(
minimum: 0, alignment: Alignment.center,
showLabels: false, children: <Widget>[
showTicks: false, SfRadialGauge(
canScaleToFit: true, axes: <RadialAxis>[
axisLineStyle: AxisLineStyle( RadialAxis(
thickness: 0.05, onAxisTapped: (val) {
thicknessUnit: GaugeSizeUnit.factor, _setBrightness(val, entity);
color: HAClientTheme().getDisabledStateColor(context) },
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>[ FractionallySizedBox(
/*RangePointer( heightFactor: 0.4,
value: value, widthFactor: 0.4,
sizeUnit: GaugeSizeUnit.factor, child: AspectRatio(
width: 0.05, aspectRatio: 1,
color: HAClientTheme().getOnStateColor(context), child: InkResponse(
enableAnimation: true, onTap: () => entityWrapper.handleTap(),
animationType: AnimationType.bounceOut, onLongPress: () => entityWrapper.handleHold(),
),*/ child: FittedBox(
MarkerPointer( fit: BoxFit.contain,
value: value, child: EntityIcon(
markerType: MarkerType.circle, showBadge: false,
markerHeight: 20, padding: EdgeInsets.all(0)
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,
) )
] )
) ],
], )
), )
], ),
) 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: