From eb3aac0231e8ce00a4cba24c3c2e575630bb38fe Mon Sep 17 00:00:00 2001 From: Tommy Chow Date: Tue, 12 Oct 2021 02:34:30 -0400 Subject: [PATCH] Move home observers for more granular rebuilds --- lib/screens/home.dart | 59 ++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 095e61f5..d69ca509 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -32,12 +32,11 @@ class _HomeState extends State { final titles = [if (context.read().isLoggedIn) 'Followed Channels', 'Top Channels', 'Categories']; debugPrint('build home'); - return Observer( - builder: (_) { - debugPrint('rebuild tab controller'); - return Scaffold( - appBar: AppBar( - title: widget.homeStore.search + return Scaffold( + appBar: AppBar( + title: Observer( + builder: (_) { + return widget.homeStore.search ? TextField( controller: _textController, autocorrect: false, @@ -62,19 +61,23 @@ class _HomeState extends State { _textController.clear(); }, ) - : Text(titles[widget.homeStore.selectedIndex]), - actions: [ - IconButton( - icon: widget.homeStore.search ? const Icon(Icons.cancel) : const Icon(Icons.search), - onPressed: () { - widget.homeStore.search = !widget.homeStore.search; - _textController.clear(); - }, - ) - ], - ), - drawer: const DrawerMenu(), - body: IndexedStack( + : Text(titles[widget.homeStore.selectedIndex]); + }, + ), + actions: [ + IconButton( + icon: Observer(builder: (_) => widget.homeStore.search ? const Icon(Icons.cancel) : const Icon(Icons.search)), + onPressed: () { + widget.homeStore.search = !widget.homeStore.search; + _textController.clear(); + }, + ) + ], + ), + drawer: const DrawerMenu(), + body: Observer( + builder: (_) { + return IndexedStack( index: widget.homeStore.selectedIndex, children: [ if (context.read().isLoggedIn) @@ -90,9 +93,13 @@ class _HomeState extends State { child: Text('Games'), ), ], - ), - bottomNavigationBar: SafeArea( - child: BottomNavigationBar( + ); + }, + ), + bottomNavigationBar: SafeArea( + child: Observer( + builder: (_) { + return BottomNavigationBar( items: [ if (context.read().isLoggedIn) const BottomNavigationBarItem( @@ -110,10 +117,10 @@ class _HomeState extends State { ], currentIndex: widget.homeStore.selectedIndex, onTap: widget.homeStore.handleTap, - ), - ), - ); - }, + ); + }, + ), + ), ); }