2019-09-07 18:23:04 +03:00
|
|
|
part of 'main.dart';
|
2018-10-27 17:28:47 +03:00
|
|
|
|
|
|
|
class HAView {
|
2020-04-27 01:46:37 +03:00
|
|
|
List<CardData> cards = [];
|
2018-10-27 17:28:47 +03:00
|
|
|
Entity linkedEntity;
|
2020-03-22 01:11:00 +02:00
|
|
|
String name;
|
|
|
|
String id;
|
|
|
|
String iconName;
|
2019-09-07 17:58:00 +03:00
|
|
|
final int count;
|
2020-03-22 01:11:00 +02:00
|
|
|
bool isPanel;
|
2018-10-27 17:28:47 +03:00
|
|
|
|
2020-03-22 01:11:00 +02:00
|
|
|
HAView({@required this.count, @required rawData}) {
|
|
|
|
id = "${rawData['id']}";
|
|
|
|
name = rawData['title'];
|
|
|
|
iconName = rawData['icon'];
|
|
|
|
isPanel = rawData['panel'] ?? false;
|
|
|
|
|
2020-05-09 16:38:05 +03:00
|
|
|
if (rawData['badges'] != null && !isPanel) {
|
|
|
|
cards.add(CardData.parse({
|
|
|
|
'type': CardType.BADGES,
|
|
|
|
'badges': rawData['badges']
|
|
|
|
}));
|
2020-03-22 01:11:00 +02:00
|
|
|
}
|
|
|
|
|
2020-05-09 16:38:05 +03:00
|
|
|
(rawData['cards'] ?? []).forEach((rawCardData) {
|
2020-04-27 01:46:37 +03:00
|
|
|
cards.add(CardData.parse(rawCardData));
|
|
|
|
});
|
2018-10-27 17:28:47 +03:00
|
|
|
}
|
|
|
|
|
2018-11-04 22:19:45 +02:00
|
|
|
Widget buildTab() {
|
|
|
|
if (linkedEntity == null) {
|
2020-03-12 23:16:07 +02:00
|
|
|
if (iconName != null && iconName.isNotEmpty) {
|
2018-11-04 22:19:45 +02:00
|
|
|
return
|
|
|
|
Tab(
|
|
|
|
icon:
|
|
|
|
Icon(
|
2019-02-22 15:15:27 +02:00
|
|
|
MaterialDesignIcons.getIconDataFromIconName(
|
2018-11-04 22:19:45 +02:00
|
|
|
iconName ?? "mdi:home-assistant"),
|
|
|
|
size: 24.0,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return
|
|
|
|
Tab(
|
2019-09-18 21:14:21 +03:00
|
|
|
text: "${name?.toUpperCase() ?? "UNNAMED VIEW"}",
|
2018-11-04 22:19:45 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (linkedEntity.icon != null && linkedEntity.icon.length > 0) {
|
|
|
|
return Tab(
|
|
|
|
icon: Icon(
|
2019-02-22 15:15:27 +02:00
|
|
|
MaterialDesignIcons.getIconDataFromIconName(
|
2018-11-04 22:19:45 +02:00
|
|
|
linkedEntity.icon),
|
|
|
|
size: 24.0,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Tab(
|
2019-09-18 21:14:21 +03:00
|
|
|
text: "${linkedEntity.displayName?.toUpperCase()}",
|
2018-11-04 22:19:45 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-27 17:28:47 +03:00
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ViewWidget(
|
|
|
|
view: this,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|