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
2020-05-09 18:08:42 +00:00

72 lines
1.6 KiB
Dart

part of 'main.dart';
class HAView {
List<CardData> cards = [];
CardData badges;
Entity linkedEntity;
String name;
String id;
String iconName;
final int count;
bool isPanel;
HAView({@required this.count, @required rawData}) {
id = "${rawData['id']}";
name = rawData['title'];
iconName = rawData['icon'];
isPanel = rawData['panel'] ?? false;
if (rawData['badges'] != null && !isPanel) {
badges = CardData.parse({
'type': CardType.BADGES,
'badges': rawData['badges']
});
}
(rawData['cards'] ?? []).forEach((rawCardData) {
cards.add(CardData.parse(rawCardData));
});
}
Widget buildTab() {
if (linkedEntity == null) {
if (iconName != null && iconName.isNotEmpty) {
return
Tab(
icon:
Icon(
MaterialDesignIcons.getIconDataFromIconName(
iconName ?? "mdi:home-assistant"),
size: 24.0,
)
);
} else {
return
Tab(
text: "${name?.toUpperCase() ?? "UNNAMED VIEW"}",
);
}
} else {
if (linkedEntity.icon != null && linkedEntity.icon.length > 0) {
return Tab(
icon: Icon(
MaterialDesignIcons.getIconDataFromIconName(
linkedEntity.icon),
size: 24.0,
)
);
} else {
return Tab(
text: "${linkedEntity.displayName?.toUpperCase()}",
);
}
}
}
Widget build(BuildContext context) {
return ViewWidget(
view: this,
);
}
}