This repository has been archived on 2023-11-18. You can view files and clone it, but cannot push or open issues or pull requests.
ha_client/lib/cards/card_widget.dart

98 lines
2.3 KiB
Dart
Raw Normal View History

2019-09-07 18:23:04 +03:00
part of '../main.dart';
2020-04-25 20:38:21 +03:00
class LovelaceCard extends StatelessWidget {
final HACard card;
2020-04-25 20:38:21 +03:00
const LovelaceCard({
Key key,
this.card
}) : super(key: key);
@override
Widget build(BuildContext context) {
2019-03-12 23:35:33 +02:00
if (card.linkedEntityWrapper!= null) {
if (card.linkedEntityWrapper.entity.isHidden) {
return Container(width: 0.0, height: 0.0,);
}
if (card.linkedEntityWrapper.entity.statelessType == StatelessEntityType.MISSED) {
2019-03-12 23:35:33 +02:00
return EntityModel(
entityWrapper: card.linkedEntityWrapper,
child: MissedEntityWidget(),
handleTap: false,
);
}
}
if (card.conditions.isNotEmpty) {
2019-09-09 13:36:33 +03:00
bool showCardByConditions = true;
for (var condition in card.conditions) {
Entity conditionEntity = HomeAssistant().entities.get(condition['entity']);
if (conditionEntity != null &&
2019-09-09 13:36:33 +03:00
((condition['state'] != null && conditionEntity.state != condition['state']) ||
(condition['state_not'] != null && conditionEntity.state == condition['state_not']))
) {
2019-09-09 13:36:33 +03:00
showCardByConditions = false;
break;
}
}
if (!showCardByConditions) {
return Container(width: 0.0, height: 0.0,);
}
}
switch (card.type) {
2019-09-07 15:47:09 +03:00
case CardType.ENTITIES: {
2020-04-25 20:38:21 +03:00
return EntitiesCard(card: card);
}
2019-09-07 15:47:09 +03:00
case CardType.GLANCE: {
2020-04-25 18:59:07 +03:00
return GlanceCard(card: card);
}
2019-09-07 15:47:09 +03:00
case CardType.MEDIA_CONTROL: {
2020-04-25 20:38:21 +03:00
return MediaControlsCard(card: card);
}
2019-09-07 15:47:09 +03:00
case CardType.ENTITY_BUTTON: {
2020-04-25 18:59:07 +03:00
return EntityButtonCard(card: card);
2020-04-13 21:17:14 +03:00
}
case CardType.BUTTON: {
2020-04-25 18:59:07 +03:00
return EntityButtonCard(card: card);
}
2019-09-07 15:47:09 +03:00
case CardType.GAUGE: {
2020-04-25 18:59:07 +03:00
return GaugeCard(card: card);
2019-09-07 15:47:09 +03:00
}
case CardType.MARKDOWN: {
2020-04-25 20:38:21 +03:00
return MarkdownCard(card: card);
2019-01-23 23:34:45 +02:00
}
2019-09-07 15:47:09 +03:00
case CardType.ALARM_PANEL: {
2020-04-25 20:38:21 +03:00
return AlarmPanelCard(card: card);
2019-01-29 15:00:15 +02:00
}
2019-09-07 15:47:09 +03:00
case CardType.HORIZONTAL_STACK: {
2020-04-25 20:38:21 +03:00
return HorizontalStackCard(card: card);
}
2019-09-07 15:47:09 +03:00
case CardType.VERTICAL_STACK: {
2020-04-25 20:38:21 +03:00
return VerticalStackCard(card: card);
}
default: {
if ((card.linkedEntityWrapper == null) && (card.entities.isNotEmpty)) {
2020-04-25 20:38:21 +03:00
return EntitiesCard(card: card);
} else {
2020-04-25 20:38:21 +03:00
return UnsupportedCard(card: card);
}
}
}
}
2019-08-27 12:05:33 +03:00
}