parent
c0fb90d480
commit
e49f23ff65
2869
lib/data_model.dart
2869
lib/data_model.dart
File diff suppressed because it is too large
Load Diff
104
lib/main.dart
104
lib/main.dart
@ -44,6 +44,7 @@ class _MainPageState extends State<MainPage> {
|
|||||||
HassioDataModel _dataModel;
|
HassioDataModel _dataModel;
|
||||||
Map _entitiesData;
|
Map _entitiesData;
|
||||||
Map _uiStructure;
|
Map _uiStructure;
|
||||||
|
int _uiViewsCount = 0;
|
||||||
String _dataModelErrorMessage = "";
|
String _dataModelErrorMessage = "";
|
||||||
bool loading = true;
|
bool loading = true;
|
||||||
Map _stateIconColors = {
|
Map _stateIconColors = {
|
||||||
@ -82,6 +83,7 @@ class _MainPageState extends State<MainPage> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
_entitiesData = _dataModel.entities;
|
_entitiesData = _dataModel.entities;
|
||||||
_uiStructure = _dataModel.uiStructure;
|
_uiStructure = _dataModel.uiStructure;
|
||||||
|
_uiViewsCount = _uiStructure.length;
|
||||||
loading = false;
|
loading = false;
|
||||||
});
|
});
|
||||||
}).catchError((e) {
|
}).catchError((e) {
|
||||||
@ -138,16 +140,16 @@ class _MainPageState extends State<MainPage> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Card _buildEntityGroup(List<String> ids, String name) {
|
Card _buildCard(List<String> ids, String name) {
|
||||||
List<Widget> body = [];
|
List<Widget> body = [];
|
||||||
body.add(_buildEntityGroupHeader(name));
|
body.add(_buildCardHeader(name));
|
||||||
body.addAll(_buildEntityGroupBody(ids));
|
body.addAll(_buildCardBody(ids));
|
||||||
Card result =
|
Card result =
|
||||||
Card(child: new Column(mainAxisSize: MainAxisSize.min, children: body));
|
Card(child: new Column(mainAxisSize: MainAxisSize.min, children: body));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildEntityGroupHeader(String name) {
|
Widget _buildCardHeader(String name) {
|
||||||
var result;
|
var result;
|
||||||
if (name.length > 0) {
|
if (name.length > 0) {
|
||||||
result = new ListTile(
|
result = new ListTile(
|
||||||
@ -165,7 +167,7 @@ class _MainPageState extends State<MainPage> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Widget> _buildEntityGroupBody(List<String> ids) {
|
List<Widget> _buildCardBody(List<String> ids) {
|
||||||
List<Widget> entities = [];
|
List<Widget> entities = [];
|
||||||
ids.forEach((id) {
|
ids.forEach((id) {
|
||||||
var data = _entitiesData[id];
|
var data = _entitiesData[id];
|
||||||
@ -185,15 +187,14 @@ class _MainPageState extends State<MainPage> {
|
|||||||
return entities;
|
return entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Widget> buildEntitiesView() {
|
List<Widget> buildSingleView(structure) {
|
||||||
if ((_entitiesData != null) && (_uiStructure != null)) {
|
|
||||||
List<Widget> result = [];
|
List<Widget> result = [];
|
||||||
if (_dataModelErrorMessage.length == 0) {
|
if (_dataModelErrorMessage.length == 0) {
|
||||||
_uiStructure["standalone"].forEach((entityId) {
|
structure["standalone"].forEach((entityId) {
|
||||||
result.add(_buildEntityGroup([entityId], ""));
|
result.add(_buildCard([entityId], ""));
|
||||||
});
|
});
|
||||||
_uiStructure["groups"].forEach((group) {
|
structure["groups"].forEach((group) {
|
||||||
result.add(_buildEntityGroup(
|
result.add(_buildCard(
|
||||||
group["children"], group["friendly_name"].toString()));
|
group["children"], group["friendly_name"].toString()));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -201,10 +202,30 @@ class _MainPageState extends State<MainPage> {
|
|||||||
//result.add(Text(_dataModelErrorMessage));
|
//result.add(Text(_dataModelErrorMessage));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} else {
|
|
||||||
//TODO
|
|
||||||
return [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<ListView> buildUIViews() {
|
||||||
|
List<ListView> result = [];
|
||||||
|
if ((_entitiesData != null) && (_uiStructure != null)) {
|
||||||
|
_uiStructure.forEach((viewId, structure) {
|
||||||
|
result.add(ListView(
|
||||||
|
children: buildSingleView(structure),
|
||||||
|
));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Tab> buildUIViewTabs() {
|
||||||
|
List<Tab> result = [];
|
||||||
|
if ((_entitiesData != null) && (_uiStructure != null)) {
|
||||||
|
_uiStructure.forEach((viewId, structure) {
|
||||||
|
result.add(
|
||||||
|
Tab(icon: Icon(IconData(structure["iconCode"], fontFamily: 'Material Design Icons')))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildTitle() {
|
Widget _buildTitle() {
|
||||||
@ -223,21 +244,8 @@ class _MainPageState extends State<MainPage> {
|
|||||||
return titleRow;
|
return titleRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
Drawer _buildAppDrawer() {
|
||||||
Widget build(BuildContext context) {
|
return new Drawer(
|
||||||
// This method is rerun every time setState is called, for instance as done
|
|
||||||
// by the _incrementCounter method above.
|
|
||||||
//
|
|
||||||
// The Flutter framework has been optimized to make rerunning build methods
|
|
||||||
// fast, so that you can just rebuild anything that needs updating rather
|
|
||||||
// than having to individually change instances of widgets.
|
|
||||||
return new Scaffold(
|
|
||||||
appBar: new AppBar(
|
|
||||||
// Here we take the value from the MyHomePage object that was created by
|
|
||||||
// the App.build method, and use it to set our appbar title.
|
|
||||||
title: _buildTitle(),
|
|
||||||
),
|
|
||||||
drawer: new Drawer(
|
|
||||||
child: ListView(
|
child: ListView(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new UserAccountsDrawerHeader(
|
new UserAccountsDrawerHeader(
|
||||||
@ -262,14 +270,50 @@ class _MainPageState extends State<MainPage> {
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
// This method is rerun every time setState is called.
|
||||||
|
//
|
||||||
|
if (_entitiesData == null) {
|
||||||
|
return new Scaffold(
|
||||||
|
appBar: new AppBar(
|
||||||
|
title: _buildTitle()
|
||||||
),
|
),
|
||||||
body: ListView(children: buildEntitiesView()),
|
drawer: _buildAppDrawer(),
|
||||||
|
body: Text("Loading... or not...\n\nPlease, restart the app in case of three dots in header starts to freaking you out."),
|
||||||
floatingActionButton: new FloatingActionButton(
|
floatingActionButton: new FloatingActionButton(
|
||||||
onPressed: _refreshData,
|
onPressed: _refreshData,
|
||||||
tooltip: 'Increment',
|
tooltip: 'Increment',
|
||||||
child: new Icon(Icons.refresh),
|
child: new Icon(Icons.refresh),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
return DefaultTabController(
|
||||||
|
length: _uiViewsCount,
|
||||||
|
child: new Scaffold(
|
||||||
|
appBar: new AppBar(
|
||||||
|
// Here we take the value from the MyHomePage object that was created by
|
||||||
|
// the App.build method, and use it to set our appbar title.
|
||||||
|
title: _buildTitle(),
|
||||||
|
bottom: TabBar(
|
||||||
|
tabs: buildUIViewTabs()
|
||||||
|
),
|
||||||
|
),
|
||||||
|
drawer: _buildAppDrawer(),
|
||||||
|
body: TabBarView(
|
||||||
|
children: buildUIViews()
|
||||||
|
),
|
||||||
|
floatingActionButton: new FloatingActionButton(
|
||||||
|
onPressed: _refreshData,
|
||||||
|
tooltip: 'Increment',
|
||||||
|
child: new Icon(Icons.refresh),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
Reference in New Issue
Block a user