diff --git a/lib/screens/main_page.dart b/lib/screens/main_page.dart index 4fdbe80..f76fa08 100644 --- a/lib/screens/main_page.dart +++ b/lib/screens/main_page.dart @@ -30,18 +30,22 @@ class MainPage extends StatefulWidget { } } -class MainPageState extends State { +class MainPageState extends State + with SingleTickerProviderStateMixin { ScrollController _scrollViewController; + TabController _tabController; @override void initState() { super.initState(); _scrollViewController = new ScrollController(); + _tabController = new TabController(vsync: this, length: 2); } @override void dispose() { _scrollViewController.dispose(); + _tabController.dispose(); super.dispose(); } @@ -65,48 +69,49 @@ class MainPageState extends State { _scrollToTop(); viewModel.acceptEntryAddedCallback(); } - return new DefaultTabController( - length: 2, - child: new Scaffold( - body: new NestedScrollView( - controller: _scrollViewController, - headerSliverBuilder: - (BuildContext context, bool innerBoxIsScrolled) { - return [ - new SliverAppBar( - title: new Text(widget.title), - pinned: true, - floating: true, - forceElevated: innerBoxIsScrolled, - bottom: new TabBar( - tabs: [ - new Tab( - text: "STATISTICS", - icon: new Icon(Icons.show_chart), - ), - new Tab( - text: "HISTORY", - icon: new Icon(Icons.history), - ), - ], - ), + return new Scaffold( + body: new NestedScrollView( + controller: _scrollViewController, + headerSliverBuilder: + (BuildContext context, bool innerBoxIsScrolled) { + return [ + new SliverAppBar( + title: new Text(widget.title), + pinned: true, + floating: true, + forceElevated: innerBoxIsScrolled, + bottom: new TabBar( + tabs: [ + new Tab( + text: "STATISTICS", + icon: new Icon(Icons.show_chart), + ), + new Tab( + text: "HISTORY", + icon: new Icon(Icons.history), + ), + ], + controller: _tabController, ), - ]; - }, - body: new TabBarView( - children: [ - new StatisticsPage(), - new HistoryPage(), - ], - ), - ), - floatingActionButton: new FloatingActionButton( - onPressed: () => _openAddEntryDialog( - viewModel.defaultWeight, context, viewModel.addEntryCallback), - tooltip: 'Add new weight entry', - child: new Icon(Icons.add), + ), + ]; + }, + body: new TabBarView( + children: [ + new StatisticsPage(), + new HistoryPage(), + ], + controller: _tabController, ), ), + floatingActionButton: new FloatingActionButton( + onPressed: () => + _openAddEntryDialog( + viewModel.defaultWeight, context, + viewModel.addEntryCallback), + tooltip: 'Add new weight entry', + child: new Icon(Icons.add), + ), ); }, );