From 0f6babc243dc7824a689ad9d25eaceb038543e05 Mon Sep 17 00:00:00 2001 From: Yegor Vialov Date: Sun, 21 Oct 2018 16:11:47 +0300 Subject: [PATCH] Resolves #151 Group visibility support --- lib/card_class.dart | 11 +++++++++-- lib/entity_class/entity.class.dart | 1 + lib/view_class.dart | 20 +++++++++++++++----- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/card_class.dart b/lib/card_class.dart index 68b64a6..bbd3bf6 100644 --- a/lib/card_class.dart +++ b/lib/card_class.dart @@ -1,11 +1,11 @@ part of 'main.dart'; -class HACard extends StatelessWidget { +class CardWidget extends StatelessWidget { final List entities; final String friendlyName; - const HACard({ + const CardWidget({ Key key, this.entities, this.friendlyName @@ -13,6 +13,13 @@ class HACard extends StatelessWidget { @override Widget build(BuildContext context) { + final entityModel = EntityModel.of(context); + if (entityModel != null) { + final groupEntity = entityModel.entity; + if (groupEntity.isHidden) { + return Container(width: 0.0, height: 0.0,); + } + } List body = []; body.add(_buildCardHeader()); body.addAll(_buildCardBody(context)); diff --git a/lib/entity_class/entity.class.dart b/lib/entity_class/entity.class.dart index 0d1c84c..391f17d 100644 --- a/lib/entity_class/entity.class.dart +++ b/lib/entity_class/entity.class.dart @@ -62,6 +62,7 @@ class Entity { String get unitOfMeasurement => attributes["unit_of_measurement"] ?? ""; List get childEntityIds => attributes["entity_id"] ?? []; String get lastUpdated => _getLastUpdatedFormatted(); + bool get isHidden => attributes["hidden"] ?? false; Entity(Map rawData) { update(rawData); diff --git a/lib/view_class.dart b/lib/view_class.dart index cd6fb15..2763c32 100644 --- a/lib/view_class.dart +++ b/lib/view_class.dart @@ -41,6 +41,7 @@ class View { } else { childEntitiesAsCards[entity.entityId] = CardSkeleton( displayName: entity.displayName, + groupEntity: entity ); childEntitiesAsCards[entity.entityId].childEntities = entity.childEntities; } @@ -111,10 +112,14 @@ class ViewWidgetState extends State { widget.cards.forEach((String id, CardSkeleton skeleton){ result.add( - HACard( - entities: skeleton.childEntities, - friendlyName: skeleton.displayName, - ) + EntityModel( + entity: skeleton.groupEntity, + handleTap: false, + child: CardWidget( + entities: skeleton.childEntities, + friendlyName: skeleton.displayName, + ) + ) ); }); @@ -151,8 +156,13 @@ class ViewWidgetState extends State { class CardSkeleton { String displayName; List childEntities; + Entity groupEntity; - CardSkeleton({Key key, this.displayName, this.childEntities}) { + CardSkeleton({ + Key key, + this.displayName, + this.childEntities, + this.groupEntity}) { childEntities = []; } } \ No newline at end of file