From 05c1427aa87731abfea7bdd6cd73a0534a1deaec Mon Sep 17 00:00:00 2001 From: Yegor Vialov Date: Sat, 25 Apr 2020 18:23:26 +0000 Subject: [PATCH] Add icon support for entities card title --- lib/cards/card.class.dart | 2 ++ lib/cards/entities_card.dart | 29 +++++++++++++---------- lib/cards/widgets/card_header.widget.dart | 4 +++- lib/view.class.dart | 1 + 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/lib/cards/card.class.dart b/lib/cards/card.class.dart index 286ae50..d694a54 100644 --- a/lib/cards/card.class.dart +++ b/lib/cards/card.class.dart @@ -7,6 +7,7 @@ class HACard { String name; String id; String type; + String icon; bool showName; bool showState; bool showEmpty; @@ -40,6 +41,7 @@ class HACard { this.max, this.depth: 1, this.severity, + this.icon, @required this.type }) { if (this.columnsCount <= 0) { diff --git a/lib/cards/entities_card.dart b/lib/cards/entities_card.dart index 8b12a1c..0b9380c 100644 --- a/lib/cards/entities_card.dart +++ b/lib/cards/entities_card.dart @@ -21,23 +21,28 @@ class EntitiesCard extends StatelessWidget { return en.entity.entityId; }).toList(); headerSwitch = Switch( - value: headerToggleVal, - onChanged: (val) { - if (entitiesToToggle.isNotEmpty) { - ConnectionManager().callService( - domain: "homeassistant", - service: val ? "turn_on" : "turn_off", - entityId: entitiesToToggle - ); - } - }, - ); + value: headerToggleVal, + onChanged: (val) { + if (entitiesToToggle.isNotEmpty) { + ConnectionManager().callService( + domain: "homeassistant", + service: val ? "turn_on" : "turn_off", + entityId: entitiesToToggle + ); + } + }, + ); } body.add( CardHeader( name: card.name, trailing: headerSwitch, - emptyPadding: Sizes.rowPadding + emptyPadding: Sizes.rowPadding, + leading: card.icon != null ? Icon( + MaterialDesignIcons.getIconDataFromIconName(card.icon), + size: Sizes.iconSize, + color: Theme.of(context).textTheme.headline.color + ) : null, ) ); body.addAll( diff --git a/lib/cards/widgets/card_header.widget.dart b/lib/cards/widgets/card_header.widget.dart index 3f4554e..24533d0 100644 --- a/lib/cards/widgets/card_header.widget.dart +++ b/lib/cards/widgets/card_header.widget.dart @@ -4,10 +4,11 @@ class CardHeader extends StatelessWidget { final String name; final Widget trailing; + final Widget leading; final Widget subtitle; final double emptyPadding; - const CardHeader({Key key, this.name, this.emptyPadding: 0, this.trailing, this.subtitle}) : super(key: key); + const CardHeader({Key key, this.name, this.leading, this.emptyPadding: 0, this.trailing, this.subtitle}) : super(key: key); @override Widget build(BuildContext context) { @@ -15,6 +16,7 @@ class CardHeader extends StatelessWidget { if ((name != null) && (name.trim().length > 0)) { result = new ListTile( trailing: trailing, + leading: leading, subtitle: subtitle, title: Text("$name", textAlign: TextAlign.left, diff --git a/lib/view.class.dart b/lib/view.class.dart index 092465b..1a24c1f 100644 --- a/lib/view.class.dart +++ b/lib/view.class.dart @@ -46,6 +46,7 @@ class HAView { id: "card", name: rawCardInfo["title"] ?? rawCardInfo["name"], type: rawCardInfo['type'] ?? CardType.ENTITIES, + icon: rawCardInfo['icon'], columnsCount: rawCardInfo['columns'] ?? 4, showName: (rawCardInfo['show_name'] ?? rawCard['show_name']) ?? true, showHeaderToggle: (rawCardInfo['show_header_toggle'] ?? rawCard['show_header_toggle']) ?? false,