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_builder.class.dart

88 lines
1.9 KiB
Dart
Raw Normal View History

2018-10-07 02:17:14 +03:00
part of 'main.dart';
class ViewBuilder{
EntityCollection entityCollection;
List<View> _views;
ViewBuilder({
Key key,
this.entityCollection
}) {
_compose();
}
Widget buildWidget(BuildContext context) {
2018-10-21 02:39:51 +03:00
return ViewBuilderWidget(
entities: _views
2018-10-07 02:17:14 +03:00
);
}
void _compose() {
TheLogger.log("Debug", "Rebuilding all UI...");
_views = [];
if (!entityCollection.hasDefaultView) {
_views.add(_composeDefaultView());
}
_views.addAll(_composeViews());
}
View _composeDefaultView() {
Map<String, List<String>> userGroupsList = entityCollection.getDefaultViewTopLevelEntities();
List<Entity> entitiesForView = [];
userGroupsList["userGroups"].forEach((groupId){
2018-10-18 21:57:10 +03:00
Entity en = entityCollection.get(groupId);
entitiesForView.add(en);
2018-10-07 02:17:14 +03:00
});
userGroupsList["notGroupedEntities"].forEach((entityId){
entitiesForView.add(entityCollection.get(entityId));
});
return View(
2018-10-21 02:39:51 +03:00
entities: entitiesForView,
2018-10-07 02:17:14 +03:00
count: 0
);
}
List<View> _composeViews() {
List<View> result = [];
int counter = 0;
entityCollection.views.forEach((viewId, viewGroupEntity) {
2018-10-07 02:17:14 +03:00
counter += 1;
//try {
result.add(View(
count: counter,
entities: viewGroupEntity.childEntities
2018-10-07 02:17:14 +03:00
));
/*} catch (error) {
TheLogger.log("Error","Error parsing view: $viewId");
}*/
});
return result;
}
2018-10-21 02:39:51 +03:00
}
class ViewBuilderWidget extends StatelessWidget {
final List<View> entities;
const ViewBuilderWidget({
Key key,
this.entities
}) : super(key: key);
@override
Widget build(BuildContext context) {
return TabBarView(
children: _buildChildren(context)
);
}
List<Widget> _buildChildren(BuildContext context) {
List<Widget> result = [];
entities.forEach((View view){
result.add(view.buildWidget(context));
});
return result;
}
2018-10-07 02:17:14 +03:00
}