From 1a7457abf9a5775a518391a652e0ed53abb60c77 Mon Sep 17 00:00:00 2001 From: estevez-dev Date: Fri, 22 Feb 2019 15:28:11 +0200 Subject: [PATCH] Resolves #311 Rebuild tabs only if views count changes --- lib/main.dart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/main.dart b/lib/main.dart index 68d2607..4c1de75 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -161,6 +161,7 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker bool _settingsLoaded = false; bool _accountMenuExpanded = false; bool _useLovelaceUI; + int _previousViewCount; @override void initState() { @@ -255,7 +256,12 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker _showInfoBottomBar(progress: true,); await _homeAssistant.fetch().then((result) { _hideBottomBar(); - _viewsTabController = TabController(vsync: this, length: _homeAssistant.ui?.views?.length ?? 0); + int currentViewCount = _homeAssistant.ui?.views?.length ?? 0; + if (_previousViewCount != currentViewCount) { + Logger.d("Views count changed ($_previousViewCount->$currentViewCount). Creating new tabs controller."); + _viewsTabController = TabController(vsync: this, length: currentViewCount); + _previousViewCount = currentViewCount; + } }).catchError((e) { _setErrorState(e); });