From f488c0810b38e732de6bb9341a5a3f2cb76da8dd Mon Sep 17 00:00:00 2001 From: Yegor Vialov Date: Sat, 25 Apr 2020 15:59:07 +0000 Subject: [PATCH] WIP: Cards build optimization --- lib/cards/card_widget.dart | 129 ++----------- lib/cards/entity_button_card.dart | 62 +++++++ lib/cards/gauge_card.dart | 174 ++++++++++++++++++ lib/cards/glance_card.dart | 114 ++++++++++++ lib/cards/widgets/card_header.widget.dart | 2 +- ...ace_card.dart => card_wrapper.widget.dart} | 4 +- .../entity_button_card_body.widget.dart | 51 ----- lib/cards/widgets/gauge_card_body.dart | 165 ----------------- .../widgets/glance_card_entity_container.dart | 84 --------- lib/cards/widgets/light_card_body.dart | 32 ---- lib/main.dart | 9 +- 11 files changed, 371 insertions(+), 455 deletions(-) create mode 100644 lib/cards/entity_button_card.dart create mode 100644 lib/cards/gauge_card.dart create mode 100644 lib/cards/glance_card.dart rename lib/cards/widgets/{lovelace_card.dart => card_wrapper.widget.dart} (58%) delete mode 100644 lib/cards/widgets/entity_button_card_body.widget.dart delete mode 100644 lib/cards/widgets/gauge_card_body.dart delete mode 100644 lib/cards/widgets/glance_card_entity_container.dart delete mode 100644 lib/cards/widgets/light_card_body.dart diff --git a/lib/cards/card_widget.dart b/lib/cards/card_widget.dart index c2b215c..64cb4c4 100644 --- a/lib/cards/card_widget.dart +++ b/lib/cards/card_widget.dart @@ -48,7 +48,7 @@ class CardWidget extends StatelessWidget { } case CardType.GLANCE: { - return _buildGlanceCard(context); + return GlanceCard(card: card); } case CardType.MEDIA_CONTROL: { @@ -56,15 +56,15 @@ class CardWidget extends StatelessWidget { } case CardType.ENTITY_BUTTON: { - return _buildEntityButtonCard(context); + return EntityButtonCard(card: card); } case CardType.BUTTON: { - return _buildEntityButtonCard(context); + return EntityButtonCard(card: card); } case CardType.GAUGE: { - return _buildGaugeCard(context); + return GaugeCard(card: card); } /* case CardType.LIGHT: { @@ -167,9 +167,13 @@ class CardWidget extends StatelessWidget { ); }) ); - return LovelaceCard( + return CardWrapper( child: Padding( - padding: EdgeInsets.only(right: Sizes.rightWidgetPadding, left: Sizes.leftWidgetPadding), + padding: EdgeInsets.only( + right: Sizes.rightWidgetPadding, + left: Sizes.leftWidgetPadding, + bottom: Sizes.rowPadding, + ), child: Column( mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.start, @@ -186,7 +190,7 @@ class CardWidget extends StatelessWidget { List body = []; body.add(CardHeader(name: card.name)); body.add(MarkdownBody(data: card.content)); - return LovelaceCard( + return CardWrapper( child: Padding( padding: EdgeInsets.fromLTRB(Sizes.leftWidgetPadding, Sizes.rowPadding, Sizes.rightWidgetPadding, Sizes.rowPadding), child: new Column(mainAxisSize: MainAxisSize.min, children: body), @@ -226,7 +230,7 @@ class CardWidget extends StatelessWidget { states: card.states, ) ); - return LovelaceCard( + return CardWrapper( child: EntityModel( entityWrapper: card.linkedEntityWrapper, handleTap: null, @@ -239,63 +243,8 @@ class CardWidget extends StatelessWidget { ); } - Widget _buildGlanceCard(BuildContext context) { - List entitiesToShow = card.getEntitiesToShow(); - if (entitiesToShow.isEmpty && !card.showEmpty) { - return Container(height: 0.0, width: 0.0,); - } - int length = entitiesToShow.length; - int columnsCount = length >= card.columnsCount ? card.columnsCount : entitiesToShow.length; - int rowsCount = (length / columnsCount).round(); - List rows = []; - for (int i = 0; i < rowsCount; i++) { - int start = i*columnsCount; - int end = start + math.min(columnsCount, length - start); - List rowChildren = []; - rowChildren.addAll(entitiesToShow.sublist( - start, end - ).map( - (EntityWrapper entity){ - return EntityModel( - entityWrapper: entity, - child: GlanceCardEntityContainer( - showName: card.showName, - showState: card.showState, - ), - handleTap: true - ); - } - ).toList() - ); - while (rowChildren.length < columnsCount) { - rowChildren.add( - Container() - ); - } - rows.add( - TableRow( - children: rowChildren - ) - ); - } - return LovelaceCard( - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - CardHeader(name: card.name), - Padding( - padding: EdgeInsets.symmetric(vertical: Sizes.rowPadding), - child: Table( - children: rows - ) - ) - ], - ) - ); - } - Widget _buildMediaControlsCard(BuildContext context) { - return LovelaceCard( + return CardWrapper( child: EntityModel( entityWrapper: card.linkedEntityWrapper, handleTap: null, @@ -304,56 +253,6 @@ class CardWidget extends StatelessWidget { ); } - Widget _buildEntityButtonCard(BuildContext context) { - card.linkedEntityWrapper.overrideName = card.name?.toUpperCase() ?? - card.linkedEntityWrapper.displayName.toUpperCase(); - return LovelaceCard( - child: EntityModel( - entityWrapper: card.linkedEntityWrapper, - child: EntityButtonCardBody( - depth: card.depth, - showName: card.showName, - ), - handleTap: true - ) - ); - } - - Widget _buildGaugeCard(BuildContext context) { - card.linkedEntityWrapper.overrideName = card.name ?? - card.linkedEntityWrapper.displayName; - card.linkedEntityWrapper.unitOfMeasurementOverride = card.unit ?? - card.linkedEntityWrapper.unitOfMeasurement; - return LovelaceCard( - child: EntityModel( - entityWrapper: card.linkedEntityWrapper, - child: GaugeCardBody( - min: card.min, - max: card.max, - depth: card.depth, - severity: card.severity, - ), - handleTap: true - ) - ); - } - - Widget _buildLightCard(BuildContext context) { - card.linkedEntityWrapper.overrideName = card.name ?? - card.linkedEntityWrapper.displayName; - return LovelaceCard( - child: EntityModel( - entityWrapper: card.linkedEntityWrapper, - child: LightCardBody( - min: card.min, - max: card.max, - severity: card.severity, - ), - handleTap: true - ) - ); - } - Widget _buildUnsupportedCard(BuildContext context) { List body = []; body.add( @@ -382,7 +281,7 @@ class CardWidget extends StatelessWidget { ]); } body.addAll(result); - return LovelaceCard( + return CardWrapper( child: new Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, diff --git a/lib/cards/entity_button_card.dart b/lib/cards/entity_button_card.dart new file mode 100644 index 0000000..3f4e71d --- /dev/null +++ b/lib/cards/entity_button_card.dart @@ -0,0 +1,62 @@ +part of '../main.dart'; + +class EntityButtonCard extends StatelessWidget { + + final HACard card; + + EntityButtonCard({ + Key key, this.card + }) : super(key: key); + + @override + Widget build(BuildContext context) { + card.linkedEntityWrapper.overrideName = card.name?.toUpperCase() ?? + card.linkedEntityWrapper.displayName.toUpperCase(); + EntityWrapper entityWrapper = card.linkedEntityWrapper; + if (entityWrapper.entity.statelessType == StatelessEntityType.MISSED) { + return MissedEntityWidget(); + } + if (entityWrapper.entity.statelessType > StatelessEntityType.MISSED) { + return Container(width: 0.0, height: 0.0,); + } + double widthBase = math.min(MediaQuery.of(context).size.width, MediaQuery.of(context).size.height) / 6; + + + return CardWrapper( + child: Center( + child: EntityModel( + entityWrapper: card.linkedEntityWrapper, + child: InkWell( + onTap: () => entityWrapper.handleTap(), + onLongPress: () => entityWrapper.handleHold(), + onDoubleTap: () => entityWrapper.handleDoubleTap(), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + EntityIcon( + padding: EdgeInsets.fromLTRB(2.0, 6.0, 2.0, 2.0), + size: widthBase / (card.depth * 0.5), + ), + _buildName() + ], + ), + ), + handleTap: true + ), + ) + ); + } + + Widget _buildName() { + if (card.showName) { + return EntityName( + padding: EdgeInsets.fromLTRB(Sizes.buttonPadding, 0.0, Sizes.buttonPadding, Sizes.rowPadding), + textOverflow: TextOverflow.ellipsis, + maxLines: 3, + wordsWrap: true, + textAlign: TextAlign.center + ); + } + return Container(width: 0, height: 0); + } +} \ No newline at end of file diff --git a/lib/cards/gauge_card.dart b/lib/cards/gauge_card.dart new file mode 100644 index 0000000..2665388 --- /dev/null +++ b/lib/cards/gauge_card.dart @@ -0,0 +1,174 @@ +part of '../main.dart'; + +class GaugeCard extends StatelessWidget { + + final HACard card; + + GaugeCard({Key key, this.card}) : super(key: key); + + @override + Widget build(BuildContext context) { + EntityWrapper entityWrapper = card.linkedEntityWrapper; + entityWrapper.overrideName = card.name ?? + entityWrapper.displayName; + entityWrapper.unitOfMeasurementOverride = card.unit ?? + entityWrapper.unitOfMeasurement; + + double fixedValue; + double value = entityWrapper.entity.doubleState; + if (value > card.max) { + fixedValue = card.max.toDouble(); + } else if (value < card.min) { + fixedValue = card.min.toDouble(); + } else { + fixedValue = value; + } + + List ranges; + Color currentColor; + if (card.severity != null && card.severity["green"] is int && card.severity["red"] is int && card.severity["yellow"] is int) { + List rangesList = [ + RangeContainer(card.severity["green"], HAClientTheme().getGreenGaugeColor()), + RangeContainer(card.severity["red"], HAClientTheme().getRedGaugeColor()), + RangeContainer(card.severity["yellow"], HAClientTheme().getYellowGaugeColor()) + ]; + rangesList.sort((current, next) { + if (current.startFrom > next.startFrom) { + return 1; + } + if (current.startFrom < next.startFrom) { + return -1; + } + return 0; + }); + + if (fixedValue < rangesList[1].startFrom) { + currentColor = rangesList[0].color; + } else if (fixedValue < rangesList[2].startFrom && fixedValue >= rangesList[1].startFrom) { + currentColor = rangesList[1].color; + } else { + currentColor = rangesList[2].color; + } + + ranges = [ + GaugeRange( + startValue: rangesList[0].startFrom.toDouble(), + endValue: rangesList[1].startFrom.toDouble(), + color: rangesList[0].color.withOpacity(0.1), + sizeUnit: GaugeSizeUnit.factor, + endWidth: 0.3, + startWidth: 0.3 + ), + GaugeRange( + startValue: rangesList[1].startFrom.toDouble(), + endValue: rangesList[2].startFrom.toDouble(), + color: rangesList[1].color.withOpacity(0.1), + sizeUnit: GaugeSizeUnit.factor, + endWidth: 0.3, + startWidth: 0.3 + ), + GaugeRange( + startValue: rangesList[2].startFrom.toDouble(), + endValue: card.max.toDouble(), + color: rangesList[2].color.withOpacity(0.1), + sizeUnit: GaugeSizeUnit.factor, + endWidth: 0.3, + startWidth: 0.3 + ) + ]; + } + if (ranges == null) { + currentColor = Theme.of(context).primaryColorDark; + ranges = [ + GaugeRange( + startValue: card.min.toDouble(), + endValue: card.max.toDouble(), + color: Theme.of(context).primaryColorDark.withOpacity(0.1), + sizeUnit: GaugeSizeUnit.factor, + endWidth: 0.3, + startWidth: 0.3, + ) + ]; + } + + double fontSize = 30 / card.depth; + + return CardWrapper( + child: EntityModel( + entityWrapper: entityWrapper, + child: InkWell( + onTap: () => entityWrapper.handleTap(), + onLongPress: () => entityWrapper.handleHold(), + onDoubleTap: () => entityWrapper.handleDoubleTap(), + child: AspectRatio( + aspectRatio: 2, + child: SfRadialGauge( + axes: [ + RadialAxis( + maximum: card.max.toDouble(), + minimum: card.min.toDouble(), + showLabels: false, + useRangeColorForAxis: true, + showTicks: false, + canScaleToFit: true, + ranges: ranges, + axisLineStyle: AxisLineStyle( + thickness: 0.3, + thicknessUnit: GaugeSizeUnit.factor, + color: Colors.transparent + ), + annotations: [ + GaugeAnnotation( + angle: -90, + positionFactor: 1.3, + //verticalAlignment: GaugeAlignment.far, + widget: EntityName( + textStyle: Theme.of(context).textTheme.body1.copyWith( + fontSize: fontSize + ), + ), + ), + GaugeAnnotation( + angle: 180, + positionFactor: 0, + verticalAlignment: GaugeAlignment.center, + widget: SimpleEntityState( + expanded: false, + maxLines: 1, + textAlign: TextAlign.center, + textStyle: Theme.of(context).textTheme.title.copyWith( + fontSize: fontSize, + ), + ), + ) + ], + startAngle: 180, + endAngle: 0, + pointers: [ + RangePointer( + value: fixedValue, + sizeUnit: GaugeSizeUnit.factor, + width: 0.3, + color: currentColor, + enableAnimation: true, + animationType: AnimationType.bounceOut, + ) + ] + ) + ], + ) + ), + ), + handleTap: true + ) + ); + } + +} + +class RangeContainer { + final int startFrom; + Color color; + + RangeContainer(this.startFrom, this.color); +} \ No newline at end of file diff --git a/lib/cards/glance_card.dart b/lib/cards/glance_card.dart new file mode 100644 index 0000000..845e856 --- /dev/null +++ b/lib/cards/glance_card.dart @@ -0,0 +1,114 @@ +part of '../main.dart'; + +class GlanceCard extends StatelessWidget { + final HACard card; + + const GlanceCard({Key key, this.card}) : super(key: key); + + @override + Widget build(BuildContext context) { + List entitiesToShow = card.getEntitiesToShow(); + if (entitiesToShow.isEmpty && !card.showEmpty) { + return Container(height: 0.0, width: 0.0,); + } + int length = entitiesToShow.length; + int columnsCount = length >= card.columnsCount ? card.columnsCount : entitiesToShow.length; + int rowsCount = (length / columnsCount).round(); + List rows = []; + for (int i = 0; i < rowsCount; i++) { + int start = i*columnsCount; + int end = start + math.min(columnsCount, length - start); + List rowChildren = []; + rowChildren.addAll(entitiesToShow.sublist( + start, end + ).map( + (EntityWrapper entity){ + return EntityModel( + entityWrapper: entity, + child: _buildEntityContainer(context, entity), + handleTap: true + ); + } + ).toList() + ); + while (rowChildren.length < columnsCount) { + rowChildren.add( + Container() + ); + } + rows.add( + TableRow( + children: rowChildren + ) + ); + } + return CardWrapper( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + CardHeader(name: card.name), + Padding( + padding: EdgeInsets.symmetric(vertical: Sizes.rowPadding), + child: Table( + children: rows + ) + ) + ], + ) + ); + } + + Widget _buildEntityContainer(BuildContext context, EntityWrapper entityWrapper) { + if (entityWrapper.entity.statelessType == StatelessEntityType.MISSED) { + return MissedEntityWidget(); + } + if (entityWrapper.entity.statelessType > StatelessEntityType.MISSED) { + return Container(width: 0.0, height: 0.0,); + } + List result = []; + if (card.showName) { + result.add(_buildName(context)); + } + result.add( + EntityIcon( + padding: EdgeInsets.all(0.0), + size: Sizes.iconSize, + ) + ); + if (card.showState) { + result.add(_buildState()); + } + + return Center( + child: InkResponse( + child: Column( + mainAxisSize: MainAxisSize.min, + children: result, + ), + onTap: () => entityWrapper.handleTap(), + onLongPress: () => entityWrapper.handleHold(), + onDoubleTap: () => entityWrapper.handleDoubleTap(), + ), + ); + } + + Widget _buildName(BuildContext context) { + return EntityName( + padding: EdgeInsets.only(bottom: Sizes.rowPadding), + textOverflow: TextOverflow.ellipsis, + wordsWrap: false, + textAlign: TextAlign.center, + textStyle: Theme.of(context).textTheme.body1, + ); + } + + Widget _buildState() { + return SimpleEntityState( + textAlign: TextAlign.center, + expanded: false, + maxLines: 1, + padding: EdgeInsets.only(top: Sizes.rowPadding), + ); + } + +} \ No newline at end of file diff --git a/lib/cards/widgets/card_header.widget.dart b/lib/cards/widgets/card_header.widget.dart index 6ecbf14..736f663 100644 --- a/lib/cards/widgets/card_header.widget.dart +++ b/lib/cards/widgets/card_header.widget.dart @@ -21,7 +21,7 @@ class CardHeader extends StatelessWidget { style: Theme.of(context).textTheme.headline), ); } else { - result = new Container(width: 0.0, height: 0.0); + result = new Container(width: 0.0, height: Sizes.rowPadding); } return result; } diff --git a/lib/cards/widgets/lovelace_card.dart b/lib/cards/widgets/card_wrapper.widget.dart similarity index 58% rename from lib/cards/widgets/lovelace_card.dart rename to lib/cards/widgets/card_wrapper.widget.dart index 9836d97..cb1dac9 100644 --- a/lib/cards/widgets/lovelace_card.dart +++ b/lib/cards/widgets/card_wrapper.widget.dart @@ -1,10 +1,10 @@ part of '../../main.dart'; -class LovelaceCard extends StatelessWidget { +class CardWrapper extends StatelessWidget { final Widget child; - const LovelaceCard({Key key, this.child}) : super(key: key); + const CardWrapper({Key key, this.child}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/lib/cards/widgets/entity_button_card_body.widget.dart b/lib/cards/widgets/entity_button_card_body.widget.dart deleted file mode 100644 index 202ae88..0000000 --- a/lib/cards/widgets/entity_button_card_body.widget.dart +++ /dev/null @@ -1,51 +0,0 @@ -part of '../../main.dart'; - -class EntityButtonCardBody extends StatelessWidget { - - final bool showName; - final int depth; - - EntityButtonCardBody({ - Key key, this.showName: true, @required this.depth - }) : super(key: key); - - @override - Widget build(BuildContext context) { - final EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper; - if (entityWrapper.entity.statelessType == StatelessEntityType.MISSED) { - return MissedEntityWidget(); - } - if (entityWrapper.entity.statelessType > StatelessEntityType.MISSED) { - return Container(width: 0.0, height: 0.0,); - } - double widthBase = math.min(MediaQuery.of(context).size.width, MediaQuery.of(context).size.height) / 6; - return InkWell( - onTap: () => entityWrapper.handleTap(), - onLongPress: () => entityWrapper.handleHold(), - onDoubleTap: () => entityWrapper.handleDoubleTap(), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - EntityIcon( - padding: EdgeInsets.fromLTRB(2.0, 6.0, 2.0, 2.0), - size: widthBase / (depth * 0.5), - ), - _buildName() - ], - ), - ); - } - - Widget _buildName() { - if (showName) { - return EntityName( - padding: EdgeInsets.fromLTRB(Sizes.buttonPadding, 0.0, Sizes.buttonPadding, Sizes.rowPadding), - textOverflow: TextOverflow.ellipsis, - maxLines: 3, - wordsWrap: true, - textAlign: TextAlign.center - ); - } - return Container(width: 0, height: 0); - } -} \ No newline at end of file diff --git a/lib/cards/widgets/gauge_card_body.dart b/lib/cards/widgets/gauge_card_body.dart deleted file mode 100644 index 2ab0804..0000000 --- a/lib/cards/widgets/gauge_card_body.dart +++ /dev/null @@ -1,165 +0,0 @@ -part of '../../main.dart'; - -class GaugeCardBody extends StatelessWidget { - - final int min; - final int max; - final Map severity; - final int depth; - - GaugeCardBody({Key key, this.min, this.max, this.severity, @required this.depth}) : super(key: key); - - @override - Widget build(BuildContext context) { - EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper; - double fixedValue; - double value = entityWrapper.entity.doubleState; - if (value > max) { - fixedValue = max.toDouble(); - } else if (value < min) { - fixedValue = min.toDouble(); - } else { - fixedValue = value; - } - - List ranges; - Color currentColor; - if (severity != null && severity["green"] is int && severity["red"] is int && severity["yellow"] is int) { - List rangesList = [ - RangeContainer(severity["green"], HAClientTheme().getGreenGaugeColor()), - RangeContainer(severity["red"], HAClientTheme().getRedGaugeColor()), - RangeContainer(severity["yellow"], HAClientTheme().getYellowGaugeColor()) - ]; - rangesList.sort((current, next) { - if (current.startFrom > next.startFrom) { - return 1; - } - if (current.startFrom < next.startFrom) { - return -1; - } - return 0; - }); - - if (fixedValue < rangesList[1].startFrom) { - currentColor = rangesList[0].color; - } else if (fixedValue < rangesList[2].startFrom && fixedValue >= rangesList[1].startFrom) { - currentColor = rangesList[1].color; - } else { - currentColor = rangesList[2].color; - } - - ranges = [ - GaugeRange( - startValue: rangesList[0].startFrom.toDouble(), - endValue: rangesList[1].startFrom.toDouble(), - color: rangesList[0].color.withOpacity(0.1), - sizeUnit: GaugeSizeUnit.factor, - endWidth: 0.3, - startWidth: 0.3 - ), - GaugeRange( - startValue: rangesList[1].startFrom.toDouble(), - endValue: rangesList[2].startFrom.toDouble(), - color: rangesList[1].color.withOpacity(0.1), - sizeUnit: GaugeSizeUnit.factor, - endWidth: 0.3, - startWidth: 0.3 - ), - GaugeRange( - startValue: rangesList[2].startFrom.toDouble(), - endValue: max.toDouble(), - color: rangesList[2].color.withOpacity(0.1), - sizeUnit: GaugeSizeUnit.factor, - endWidth: 0.3, - startWidth: 0.3 - ) - ]; - } - if (ranges == null) { - currentColor = Theme.of(context).primaryColorDark; - ranges = [ - GaugeRange( - startValue: min.toDouble(), - endValue: max.toDouble(), - color: Theme.of(context).primaryColorDark.withOpacity(0.1), - sizeUnit: GaugeSizeUnit.factor, - endWidth: 0.3, - startWidth: 0.3, - ) - ]; - } - - double fontSize = 30 / depth; - return InkWell( - onTap: () => entityWrapper.handleTap(), - onLongPress: () => entityWrapper.handleHold(), - onDoubleTap: () => entityWrapper.handleDoubleTap(), - child: AspectRatio( - aspectRatio: 2, - child: SfRadialGauge( - axes: [ - RadialAxis( - maximum: max.toDouble(), - minimum: min.toDouble(), - showLabels: false, - useRangeColorForAxis: true, - showTicks: false, - canScaleToFit: true, - ranges: ranges, - axisLineStyle: AxisLineStyle( - thickness: 0.3, - thicknessUnit: GaugeSizeUnit.factor, - color: Colors.transparent - ), - annotations: [ - GaugeAnnotation( - angle: -90, - positionFactor: 1.3, - //verticalAlignment: GaugeAlignment.far, - widget: EntityName( - textStyle: Theme.of(context).textTheme.body1.copyWith( - fontSize: fontSize - ), - ), - ), - GaugeAnnotation( - angle: 180, - positionFactor: 0, - verticalAlignment: GaugeAlignment.center, - widget: SimpleEntityState( - expanded: false, - maxLines: 1, - textAlign: TextAlign.center, - textStyle: Theme.of(context).textTheme.title.copyWith( - fontSize: fontSize, - ), - ), - ) - ], - startAngle: 180, - endAngle: 0, - pointers: [ - RangePointer( - value: fixedValue, - sizeUnit: GaugeSizeUnit.factor, - width: 0.3, - color: currentColor, - enableAnimation: true, - animationType: AnimationType.bounceOut, - ) - ] - ) - ], - ) - ), - ); - } - -} - -class RangeContainer { - final int startFrom; - Color color; - - RangeContainer(this.startFrom, this.color); -} \ No newline at end of file diff --git a/lib/cards/widgets/glance_card_entity_container.dart b/lib/cards/widgets/glance_card_entity_container.dart deleted file mode 100644 index 2b56b0e..0000000 --- a/lib/cards/widgets/glance_card_entity_container.dart +++ /dev/null @@ -1,84 +0,0 @@ -part of '../../main.dart'; - -class GlanceCardEntityContainer extends StatelessWidget { - - final bool showName; - final bool showState; - final bool nameInTheBottom; - final double iconSize; - final bool wordsWrapInName; - - GlanceCardEntityContainer({ - Key key, - @required this.showName, - @required this.showState, - this.nameInTheBottom: false, - this.iconSize: Sizes.iconSize, - this.wordsWrapInName: false - }) : super(key: key); - - @override - Widget build(BuildContext context) { - final EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper; - if (entityWrapper.entity.statelessType == StatelessEntityType.MISSED) { - return MissedEntityWidget(); - } - if (entityWrapper.entity.statelessType > StatelessEntityType.MISSED) { - return Container(width: 0.0, height: 0.0,); - } - List result = []; - if (!nameInTheBottom) { - if (showName) { - result.add(_buildName(context)); - } - } else { - if (showState) { - result.add(_buildState()); - } - } - result.add( - EntityIcon( - padding: EdgeInsets.all(0.0), - size: iconSize, - ) - ); - if (!nameInTheBottom) { - if (showState) { - result.add(_buildState()); - } - } else { - result.add(_buildName(context)); - } - - return Center( - child: InkResponse( - child: Column( - mainAxisSize: MainAxisSize.min, - children: result, - ), - onTap: () => entityWrapper.handleTap(), - onLongPress: () => entityWrapper.handleHold(), - onDoubleTap: () => entityWrapper.handleDoubleTap(), - ), - ); - } - - Widget _buildName(BuildContext context) { - return EntityName( - padding: EdgeInsets.only(bottom: Sizes.rowPadding), - textOverflow: TextOverflow.ellipsis, - wordsWrap: wordsWrapInName, - textAlign: TextAlign.center, - textStyle: Theme.of(context).textTheme.body1, - ); - } - - Widget _buildState() { - return SimpleEntityState( - textAlign: TextAlign.center, - expanded: false, - maxLines: 1, - padding: EdgeInsets.only(top: Sizes.rowPadding), - ); - } -} \ No newline at end of file diff --git a/lib/cards/widgets/light_card_body.dart b/lib/cards/widgets/light_card_body.dart deleted file mode 100644 index 2df59bf..0000000 --- a/lib/cards/widgets/light_card_body.dart +++ /dev/null @@ -1,32 +0,0 @@ -part of '../../main.dart'; - -class LightCardBody extends StatefulWidget { - - final int min; - final int max; - final Map severity; - - LightCardBody({Key key, this.min, this.max, this.severity}) : super(key: key); - - @override - _LightCardBodyState createState() => _LightCardBodyState(); -} - -class _LightCardBodyState extends State { - - @override - Widget build(BuildContext context) { - EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper; - LightEntity entity = entityWrapper.entity; - Logger.d("Light brightness: ${entity.brightness}"); - - return FractionallySizedBox( - widthFactor: 0.5, - child: Container( - //color: Colors.redAccent, - child: Text('Pffffff'), - ), - ); - - } -} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index bfe51d0..76115d5 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -62,8 +62,7 @@ part 'entities/badge.widget.dart'; part 'entities/entity_model.widget.dart'; part 'entities/default_entity_container.widget.dart'; part 'entities/missed_entity.widget.dart'; -part 'cards/widgets/glance_card_entity_container.dart'; -part 'cards/widgets/entity_button_card_body.widget.dart'; +part 'cards/entity_button_card.dart'; part 'pages/widgets/entity_attributes_list.dart'; part 'entities/entity_icon.widget.dart'; part 'entities/entity_name.widget.dart'; @@ -136,9 +135,9 @@ part 'panels/config_panel_widget.dart'; part 'panels/widgets/link_to_web_config.dart'; part 'types/ha_error.dart'; part 'types/event_bus_events.dart'; -part 'cards/widgets/gauge_card_body.dart'; -part 'cards/widgets/light_card_body.dart'; -part 'cards/widgets/lovelace_card.dart'; +part 'cards/gauge_card.dart'; +part 'cards/widgets/card_wrapper.widget.dart'; +part 'cards/glance_card.dart'; part 'pages/play_media.page.dart'; part 'entities/entity_page_layout.widget.dart'; part 'entities/media_player/widgets/media_player_seek_bar.widget.dart';