2019-09-14 12:31:50 +03:00
|
|
|
part of 'main.dart';
|
|
|
|
|
|
|
|
class ViewWidget extends StatelessWidget {
|
|
|
|
final HAView view;
|
|
|
|
|
|
|
|
const ViewWidget({
|
|
|
|
Key key,
|
|
|
|
this.view
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-05-22 15:54:39 +03:00
|
|
|
Widget cardsContainer;
|
|
|
|
Widget badgesContainer;
|
2020-03-22 01:11:00 +02:00
|
|
|
if (this.view.isPanel) {
|
2020-05-22 15:54:39 +03:00
|
|
|
cardsContainer = _buildPanelChild(context);
|
|
|
|
badgesContainer = Container(width: 0, height: 0);
|
2019-09-14 12:31:50 +03:00
|
|
|
} else {
|
2020-05-09 21:08:42 +03:00
|
|
|
if (this.view.badges != null && this.view.badges is BadgesData) {
|
|
|
|
badgesContainer = this.view.badges.buildCardWidget();
|
|
|
|
} else {
|
|
|
|
badgesContainer = Container(width: 0, height: 0);
|
|
|
|
}
|
2020-04-03 01:04:56 +03:00
|
|
|
if (this.view.cards.isNotEmpty) {
|
|
|
|
cardsContainer = DynamicMultiColumnLayout(
|
|
|
|
minColumnWidth: Sizes.minViewColumnWidth,
|
2020-04-27 01:46:37 +03:00
|
|
|
children: this.view.cards.map((card) {
|
|
|
|
if (card.conditions.isNotEmpty) {
|
|
|
|
bool showCardByConditions = true;
|
|
|
|
for (var condition in card.conditions) {
|
|
|
|
Entity conditionEntity = HomeAssistant().entities.get(condition['entity']);
|
|
|
|
if (conditionEntity != null &&
|
|
|
|
((condition['state'] != null && conditionEntity.state != condition['state']) ||
|
|
|
|
(condition['state_not'] != null && conditionEntity.state == condition['state_not']))
|
|
|
|
) {
|
|
|
|
showCardByConditions = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!showCardByConditions) {
|
|
|
|
return Container(width: 0.0, height: 0.0,);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return card.buildCardWidget();
|
|
|
|
}).toList(),
|
2020-04-03 01:04:56 +03:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
cardsContainer = Container();
|
|
|
|
}
|
2019-09-14 12:31:50 +03:00
|
|
|
}
|
2020-05-22 15:54:39 +03:00
|
|
|
return SingleChildScrollView(
|
|
|
|
padding: EdgeInsets.all(0),
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
badgesContainer,
|
|
|
|
cardsContainer
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
2019-09-14 12:31:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildPanelChild(BuildContext context) {
|
|
|
|
if (this.view.cards != null && this.view.cards.isNotEmpty) {
|
2020-04-27 01:46:37 +03:00
|
|
|
return this.view.cards[0].buildCardWidget();
|
2019-09-14 12:31:50 +03:00
|
|
|
} else {
|
|
|
|
return Container(width: 0, height: 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|