Minor code cleaning

This commit is contained in:
estevez
2018-09-24 22:54:51 +03:00
parent 0e11c1a146
commit 772b569da5
2 changed files with 33 additions and 48 deletions

View File

@ -250,7 +250,7 @@ class HassioDataModel {
}
List data = response["result"];
TheLogger.log("Debug","Parsing ${data.length} Home Assistant entities");
List<String> uiGroups = [];
List<String> viewsList = [];
data.forEach((entity) {
try {
var composedEntity = _parseEntity(entity);
@ -258,7 +258,7 @@ class HassioDataModel {
if (composedEntity["attributes"] != null) {
if ((composedEntity["domain"] == "group") &&
(composedEntity["attributes"]["view"] == true)) {
uiGroups.add(composedEntity["entity_id"]);
viewsList.add(composedEntity["entity_id"]);
}
}
_entitiesData[entity["entity_id"]] = composedEntity;
@ -270,7 +270,7 @@ class HassioDataModel {
//Gethering information for UI
TheLogger.log("Debug","Gethering views");
int viewCounter = 0;
uiGroups.forEach((viewId) { //Each view
viewsList.forEach((viewId) { //Each view
try {
Map viewStructure = {};
viewCounter += 1;

View File

@ -242,8 +242,6 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
alignment: WrapAlignment.center,
spacing: 10.0,
runSpacing: 4.0,
//padding: new EdgeInsets.all(8.0),
//itemExtent: 40.0,
children: _buildBadges(structure["badges"]["children"]),
)
);
@ -639,30 +637,19 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
_checkShowInfo(context);
// This method is rerun every time setState is called.
//
if (_entitiesData == null) {
return new Scaffold(
Scaffold _buildScaffold(bool empty) {
return Scaffold(
key: _scaffoldKey,
appBar: new AppBar(
title: _buildAppTitle()
appBar: AppBar(
title: _buildAppTitle(),
bottom: empty ? null : TabBar(tabs: buildUIViewTabs()),
),
drawer: _buildAppDrawer(),
body: Center(
body: empty ?
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
/*Padding(
padding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 10.0),
child: Text(
_fetchErrorCode > 0 ? "Well... no.\n\nThere was an error [$_fetchErrorCode]: ${_getErrorMessageByCode(_fetchErrorCode, false)}" : "Loading...",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 16.0),
),
),*/
Icon(
MaterialDesignIcons.createIconDataFromIconName("mdi:home-assistant"),
size: 100.0,
@ -670,26 +657,24 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
),
]
),
)
:
TabBarView(
children: _buildViews()
),
);
}
@override
Widget build(BuildContext context) {
_checkShowInfo(context);
// This method is rerun every time setState is called.
if (_entitiesData == null) {
return _buildScaffold(true);
} else {
return DefaultTabController(
length: _uiViewsCount,
child: new Scaffold(
key: _scaffoldKey,
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: _buildAppTitle(),
bottom: TabBar(
tabs: buildUIViewTabs()
),
),
drawer: _buildAppDrawer(),
body: TabBarView(
children: _buildViews()
),
)
child: _buildScaffold(false)
);
}
}