From 4eeddab959cba154645b4d7b6f3d8cf82ae01609 Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Tue, 8 Dec 2015 15:50:27 -0800 Subject: [PATCH] Make the StockHome TabBar selection persistent --- examples/stocks/lib/stock_home.dart | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/stocks/lib/stock_home.dart b/examples/stocks/lib/stock_home.dart index e56d3864984..cc4b3aa698e 100644 --- a/examples/stocks/lib/stock_home.dart +++ b/examples/stocks/lib/stock_home.dart @@ -22,9 +22,18 @@ class StockHome extends StatefulComponent { class StockHomeState extends State { final GlobalKey _scaffoldKey = new GlobalKey(); - final TabBarSelection _tabBarSelection = new TabBarSelection(); bool _isSearching = false; String _searchQuery; + TabBarSelection _tabBarSelection; + + void initState() { + super.initState(); + _tabBarSelection = PageStorage.of(context)?.readState(context); + if (_tabBarSelection == null) { + _tabBarSelection = new TabBarSelection(); + PageStorage.of(context)?.writeState(context, _tabBarSelection); + } + } void _handleSearchBegin() { ModalRoute.of(context).addLocalHistoryEntry(new LocalHistoryEntry(