From f96272db205926f9f3a0e0dffdc942d7c9aa1e4a Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Tue, 19 Jan 2021 11:25:53 -0800 Subject: [PATCH] Fix restoration of search details page (#648) --- .../veggieseasons/lib/screens/search.dart | 27 ++++++++++--------- .../veggieseasons/test/restoration_test.dart | 23 ++++++++++++++++ 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/experimental/veggieseasons/lib/screens/search.dart b/experimental/veggieseasons/lib/screens/search.dart index 4b2a7cd5c..af4b5d8a0 100644 --- a/experimental/veggieseasons/lib/screens/search.dart +++ b/experimental/veggieseasons/lib/screens/search.dart @@ -99,21 +99,24 @@ class _SearchScreenState extends State with RestorationMixin { final model = Provider.of(context); return UnmanagedRestorationScope( + bucket: bucket, child: CupertinoTabView( + restorationScopeId: 'tabview', builder: (context) { return AnnotatedRegion( - value: SystemUiOverlayStyle( - statusBarBrightness: - MediaQuery.platformBrightnessOf(context)), - child: SafeArea( - bottom: false, - child: Stack( - children: [ - _buildSearchResults(model.searchVeggies(terms)), - _createSearchBox(), - ], - ), - )); + value: SystemUiOverlayStyle( + statusBarBrightness: MediaQuery.platformBrightnessOf(context), + ), + child: SafeArea( + bottom: false, + child: Stack( + children: [ + _buildSearchResults(model.searchVeggies(terms)), + _createSearchBox(), + ], + ), + ), + ); }, ), ); diff --git a/experimental/veggieseasons/test/restoration_test.dart b/experimental/veggieseasons/test/restoration_test.dart index 68ec3e982..b06449ddd 100644 --- a/experimental/veggieseasons/test/restoration_test.dart +++ b/experimental/veggieseasons/test/restoration_test.dart @@ -121,6 +121,29 @@ void main() { expect(find.text('Tangelo'), findsOneWidget); expect(find.text('Tan').hitTestable(), findsOneWidget); // search text + expect(find.text('Serving info'), findsNothing); + + // Open a details page from search + await tester.tap(find.text('Tangelo')); + await tester.pumpAndSettle(); + + expect(find.text('Tangelo'), findsOneWidget); + expect(find.text('Serving info'), findsOneWidget); + + // Restores details page + await tester.restartAndRestore(); + expect(find.text('Tangelo'), findsOneWidget); + expect(find.text('Serving info'), findsOneWidget); + + // Go back to search page, is also restored + tester.state(find.byType(Navigator).last).pop(); + await tester.pumpAndSettle(); + + expect(find.text('Serving info'), findsNothing); + expect(find.text('Apples'), findsNothing); + expect(find.text('Tangelo'), findsOneWidget); + expect(find.text('Tan').hitTestable(), findsOneWidget); // search text + expect(find.text('Calorie Target'), findsNothing); // Go to "Settings".