From 772b569da5c83643bbca31faa4a0b2d39227ff89 Mon Sep 17 00:00:00 2001 From: estevez Date: Mon, 24 Sep 2018 22:54:51 +0300 Subject: [PATCH] Minor code cleaning --- lib/data_model.dart | 6 ++-- lib/main.dart | 75 ++++++++++++++++++--------------------------- 2 files changed, 33 insertions(+), 48 deletions(-) diff --git a/lib/data_model.dart b/lib/data_model.dart index c98f4b3..7ddbfff 100644 --- a/lib/data_model.dart +++ b/lib/data_model.dart @@ -250,7 +250,7 @@ class HassioDataModel { } List data = response["result"]; TheLogger.log("Debug","Parsing ${data.length} Home Assistant entities"); - List uiGroups = []; + List 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; diff --git a/lib/main.dart b/lib/main.dart index 202b758..3700263 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -242,8 +242,6 @@ class _MainPageState extends State 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,57 +637,44 @@ class _MainPageState extends State with WidgetsBindingObserver { final GlobalKey _scaffoldKey = new GlobalKey(); + Scaffold _buildScaffold(bool empty) { + return Scaffold( + key: _scaffoldKey, + appBar: AppBar( + title: _buildAppTitle(), + bottom: empty ? null : TabBar(tabs: buildUIViewTabs()), + ), + drawer: _buildAppDrawer(), + body: empty ? + Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon( + MaterialDesignIcons.createIconDataFromIconName("mdi:home-assistant"), + size: 100.0, + color: _errorCodeToBeShown == 0 ? Colors.blue : Colors.redAccent, + ), + ] + ), + ) + : + TabBarView( + children: _buildViews() + ), + ); + } + @override Widget build(BuildContext context) { _checkShowInfo(context); // This method is rerun every time setState is called. - // if (_entitiesData == null) { - return new Scaffold( - key: _scaffoldKey, - appBar: new AppBar( - title: _buildAppTitle() - ), - drawer: _buildAppDrawer(), - body: 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, - color: _errorCodeToBeShown == 0 ? Colors.blue : Colors.redAccent, - ), - ] - ), - ), - ); + 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) ); } }