This repository has been archived on 2023-11-18. You can view files and clone it, but cannot push or open issues or pull requests.
ha_client/lib/view.class.dart

72 lines
1.6 KiB
Dart
Raw Normal View History

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 = [];
2020-05-09 21:08:42 +03:00
CardData badges;
2018-10-27 17:28:47 +03:00
Entity linkedEntity;
2020-03-22 01:11:00 +02:00
String name;
String id;
String iconName;
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) {
2020-05-09 21:08:42 +03:00
badges = CardData.parse({
2020-05-09 16:38:05 +03:00
'type': CardType.BADGES,
'badges': rawData['badges']
2020-05-09 21:08:42 +03:00
});
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) {
if (iconName != null && iconName.isNotEmpty) {
2018-11-04 22:19:45 +02:00
return
Tab(
icon:
Icon(
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(
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,
);
}
}