From a85fb3d03b6963b5b0574d15e417356fa4a4257b Mon Sep 17 00:00:00 2001 From: Yegor Vialov Date: Wed, 29 Apr 2020 20:01:37 +0000 Subject: [PATCH] Display light color as a badge on entity icon --- lib/entities/entity_icon.widget.dart | 42 ++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/lib/entities/entity_icon.widget.dart b/lib/entities/entity_icon.widget.dart index 824e048..fdfce19 100644 --- a/lib/entities/entity_icon.widget.dart +++ b/lib/entities/entity_icon.widget.dart @@ -23,12 +23,13 @@ class EntityIcon extends StatelessWidget { } } - Widget buildIcon(EntityWrapper data, Color color) { + Widget buildIcon(BuildContext context, EntityWrapper data, Color color) { + Widget result; if (data == null) { return null; } if (data.entityPicture != null) { - return Container( + result = Container( height: size+12, width: size+12, decoration: BoxDecoration( @@ -50,11 +51,45 @@ class EntityIcon extends StatelessWidget { iconCode = getDefaultIconByEntityId(data.entity.entityId, data.entity.deviceClass, data.entity.state); // } - return Icon( + result = Icon( IconData(iconCode, fontFamily: 'Material Design Icons'), size: size, color: color, ); + if (data.entity is LightEntity && + (data.entity as LightEntity).supportColor && + (data.entity as LightEntity).color != null + ) { + Color lightColor = (data.entity as LightEntity).color.toColor(); + if (lightColor == Colors.white) { + return result; + } + result = Stack( + children: [ + result, + Positioned( + bottom: 0, + right: 0, + child: Container( + width: size / 3, + height: size / 3, + decoration: BoxDecoration( + color: lightColor, + shape: BoxShape.circle, + boxShadow: [ + BoxShadow( + spreadRadius: 0, + blurRadius: 0, + offset: Offset(0.3, 0.3) + ) + ] + ), + ), + ) + ], + ); + } + return result; } @override @@ -71,6 +106,7 @@ class EntityIcon extends StatelessWidget { return Padding( padding: padding, child: buildIcon( + context, entityWrapper, iconColor ),