WIP: Cards build optimization
This commit is contained in:
parent
8dbfb91234
commit
f488c0810b
@ -48,7 +48,7 @@ class CardWidget extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case CardType.GLANCE: {
|
case CardType.GLANCE: {
|
||||||
return _buildGlanceCard(context);
|
return GlanceCard(card: card);
|
||||||
}
|
}
|
||||||
|
|
||||||
case CardType.MEDIA_CONTROL: {
|
case CardType.MEDIA_CONTROL: {
|
||||||
@ -56,15 +56,15 @@ class CardWidget extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case CardType.ENTITY_BUTTON: {
|
case CardType.ENTITY_BUTTON: {
|
||||||
return _buildEntityButtonCard(context);
|
return EntityButtonCard(card: card);
|
||||||
}
|
}
|
||||||
|
|
||||||
case CardType.BUTTON: {
|
case CardType.BUTTON: {
|
||||||
return _buildEntityButtonCard(context);
|
return EntityButtonCard(card: card);
|
||||||
}
|
}
|
||||||
|
|
||||||
case CardType.GAUGE: {
|
case CardType.GAUGE: {
|
||||||
return _buildGaugeCard(context);
|
return GaugeCard(card: card);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* case CardType.LIGHT: {
|
/* case CardType.LIGHT: {
|
||||||
@ -167,9 +167,13 @@ class CardWidget extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
return LovelaceCard(
|
return CardWrapper(
|
||||||
child: Padding(
|
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(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
@ -186,7 +190,7 @@ class CardWidget extends StatelessWidget {
|
|||||||
List<Widget> body = [];
|
List<Widget> body = [];
|
||||||
body.add(CardHeader(name: card.name));
|
body.add(CardHeader(name: card.name));
|
||||||
body.add(MarkdownBody(data: card.content));
|
body.add(MarkdownBody(data: card.content));
|
||||||
return LovelaceCard(
|
return CardWrapper(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.fromLTRB(Sizes.leftWidgetPadding, Sizes.rowPadding, Sizes.rightWidgetPadding, Sizes.rowPadding),
|
padding: EdgeInsets.fromLTRB(Sizes.leftWidgetPadding, Sizes.rowPadding, Sizes.rightWidgetPadding, Sizes.rowPadding),
|
||||||
child: new Column(mainAxisSize: MainAxisSize.min, children: body),
|
child: new Column(mainAxisSize: MainAxisSize.min, children: body),
|
||||||
@ -226,7 +230,7 @@ class CardWidget extends StatelessWidget {
|
|||||||
states: card.states,
|
states: card.states,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
return LovelaceCard(
|
return CardWrapper(
|
||||||
child: EntityModel(
|
child: EntityModel(
|
||||||
entityWrapper: card.linkedEntityWrapper,
|
entityWrapper: card.linkedEntityWrapper,
|
||||||
handleTap: null,
|
handleTap: null,
|
||||||
@ -239,63 +243,8 @@ class CardWidget extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildGlanceCard(BuildContext context) {
|
|
||||||
List<EntityWrapper> 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<TableRow> rows = [];
|
|
||||||
for (int i = 0; i < rowsCount; i++) {
|
|
||||||
int start = i*columnsCount;
|
|
||||||
int end = start + math.min(columnsCount, length - start);
|
|
||||||
List<Widget> 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: <Widget>[
|
|
||||||
CardHeader(name: card.name),
|
|
||||||
Padding(
|
|
||||||
padding: EdgeInsets.symmetric(vertical: Sizes.rowPadding),
|
|
||||||
child: Table(
|
|
||||||
children: rows
|
|
||||||
)
|
|
||||||
)
|
|
||||||
],
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildMediaControlsCard(BuildContext context) {
|
Widget _buildMediaControlsCard(BuildContext context) {
|
||||||
return LovelaceCard(
|
return CardWrapper(
|
||||||
child: EntityModel(
|
child: EntityModel(
|
||||||
entityWrapper: card.linkedEntityWrapper,
|
entityWrapper: card.linkedEntityWrapper,
|
||||||
handleTap: null,
|
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) {
|
Widget _buildUnsupportedCard(BuildContext context) {
|
||||||
List<Widget> body = [];
|
List<Widget> body = [];
|
||||||
body.add(
|
body.add(
|
||||||
@ -382,7 +281,7 @@ class CardWidget extends StatelessWidget {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
body.addAll(result);
|
body.addAll(result);
|
||||||
return LovelaceCard(
|
return CardWrapper(
|
||||||
child: new Column(
|
child: new Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
62
lib/cards/entity_button_card.dart
Normal file
62
lib/cards/entity_button_card.dart
Normal file
@ -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: <Widget>[
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
174
lib/cards/gauge_card.dart
Normal file
174
lib/cards/gauge_card.dart
Normal file
@ -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<GaugeRange> ranges;
|
||||||
|
Color currentColor;
|
||||||
|
if (card.severity != null && card.severity["green"] is int && card.severity["red"] is int && card.severity["yellow"] is int) {
|
||||||
|
List<RangeContainer> rangesList = <RangeContainer>[
|
||||||
|
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>[
|
||||||
|
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>[
|
||||||
|
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>[
|
||||||
|
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: <GaugePointer>[
|
||||||
|
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);
|
||||||
|
}
|
114
lib/cards/glance_card.dart
Normal file
114
lib/cards/glance_card.dart
Normal file
@ -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<EntityWrapper> 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<TableRow> rows = [];
|
||||||
|
for (int i = 0; i < rowsCount; i++) {
|
||||||
|
int start = i*columnsCount;
|
||||||
|
int end = start + math.min(columnsCount, length - start);
|
||||||
|
List<Widget> 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: <Widget>[
|
||||||
|
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<Widget> 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),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -21,7 +21,7 @@ class CardHeader extends StatelessWidget {
|
|||||||
style: Theme.of(context).textTheme.headline),
|
style: Theme.of(context).textTheme.headline),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
result = new Container(width: 0.0, height: 0.0);
|
result = new Container(width: 0.0, height: Sizes.rowPadding);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
part of '../../main.dart';
|
part of '../../main.dart';
|
||||||
|
|
||||||
class LovelaceCard extends StatelessWidget {
|
class CardWrapper extends StatelessWidget {
|
||||||
|
|
||||||
final Widget child;
|
final Widget child;
|
||||||
|
|
||||||
const LovelaceCard({Key key, this.child}) : super(key: key);
|
const CardWrapper({Key key, this.child}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
@ -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: <Widget>[
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -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<GaugeRange> ranges;
|
|
||||||
Color currentColor;
|
|
||||||
if (severity != null && severity["green"] is int && severity["red"] is int && severity["yellow"] is int) {
|
|
||||||
List<RangeContainer> rangesList = <RangeContainer>[
|
|
||||||
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>[
|
|
||||||
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>[
|
|
||||||
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>[
|
|
||||||
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: <GaugePointer>[
|
|
||||||
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);
|
|
||||||
}
|
|
@ -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<Widget> 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),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -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<LightCardBody> {
|
|
||||||
|
|
||||||
@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'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -62,8 +62,7 @@ part 'entities/badge.widget.dart';
|
|||||||
part 'entities/entity_model.widget.dart';
|
part 'entities/entity_model.widget.dart';
|
||||||
part 'entities/default_entity_container.widget.dart';
|
part 'entities/default_entity_container.widget.dart';
|
||||||
part 'entities/missed_entity.widget.dart';
|
part 'entities/missed_entity.widget.dart';
|
||||||
part 'cards/widgets/glance_card_entity_container.dart';
|
part 'cards/entity_button_card.dart';
|
||||||
part 'cards/widgets/entity_button_card_body.widget.dart';
|
|
||||||
part 'pages/widgets/entity_attributes_list.dart';
|
part 'pages/widgets/entity_attributes_list.dart';
|
||||||
part 'entities/entity_icon.widget.dart';
|
part 'entities/entity_icon.widget.dart';
|
||||||
part 'entities/entity_name.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 'panels/widgets/link_to_web_config.dart';
|
||||||
part 'types/ha_error.dart';
|
part 'types/ha_error.dart';
|
||||||
part 'types/event_bus_events.dart';
|
part 'types/event_bus_events.dart';
|
||||||
part 'cards/widgets/gauge_card_body.dart';
|
part 'cards/gauge_card.dart';
|
||||||
part 'cards/widgets/light_card_body.dart';
|
part 'cards/widgets/card_wrapper.widget.dart';
|
||||||
part 'cards/widgets/lovelace_card.dart';
|
part 'cards/glance_card.dart';
|
||||||
part 'pages/play_media.page.dart';
|
part 'pages/play_media.page.dart';
|
||||||
part 'entities/entity_page_layout.widget.dart';
|
part 'entities/entity_page_layout.widget.dart';
|
||||||
part 'entities/media_player/widgets/media_player_seek_bar.widget.dart';
|
part 'entities/media_player/widgets/media_player_seek_bar.widget.dart';
|
||||||
|
Reference in New Issue
Block a user