From 5bf063969b02ca032cb31be27b632547262dfc0b Mon Sep 17 00:00:00 2001 From: Yegor Vialov Date: Sun, 7 Oct 2018 17:07:06 +0300 Subject: [PATCH] Resolves #128 Enpty settings change issue --- lib/main.dart | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index c9f7a86..f454a23 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -113,21 +113,16 @@ class _MainPageState extends State with WidgetsBindingObserver { _settingsSubscription = eventBus.on().listen((event) { TheLogger.log("Debug","Settings change event: reconnect=${event.reconnect}"); if (event.reconnect) { - _homeAssistant.disconnect().then((_){ - _loadConnectionSettings().then((b){ - _refreshData(); - }, onError: (_) { - setState(() { - _isLoading = 2; - }); - _showErrorSnackBar(message: _, errorCode: 5); - } - ); - }); + _initialLoad(); } }); + _initialLoad(); + } + + void _initialLoad() { _loadConnectionSettings().then((_){ - _createConnection(); + _subscribe(); + _refreshData(); }, onError: (_) { setState(() { _isLoading = 2; @@ -161,8 +156,7 @@ class _MainPageState extends State with WidgetsBindingObserver { } } - _createConnection() { - _refreshData(); + _subscribe() { if (_stateSubscription == null) { _stateSubscription = eventBus.on().listen((event) { setState(() { @@ -203,9 +197,9 @@ class _MainPageState extends State with WidgetsBindingObserver { } _refreshData() async { - _hideErrorSnackBar(); _homeAssistant.updateConnectionSettings(_apiEndpoint, _apiPassword, _authType); setState(() { + _hideErrorSnackBar(); _isLoading = 1; }); await _homeAssistant.fetch().then((result) {