diff --git a/examples/flutter_gallery/lib/demo/pesto_demo.dart b/examples/flutter_gallery/lib/demo/pesto_demo.dart index 139fd1eee06..0ca3f44477d 100644 --- a/examples/flutter_gallery/lib/demo/pesto_demo.dart +++ b/examples/flutter_gallery/lib/demo/pesto_demo.dart @@ -9,11 +9,9 @@ import 'package:flutter/material.dart'; const String _kUserName = 'Jonathan'; const String _kUserEmail = 'jonathan@example.com'; const String _kUserImage = 'packages/flutter_gallery_assets/pesto/avatar.jpg'; -// Map of logo images keyed by the minimum height their container needs to be. -final Map _kLogoImages = { - 0.0: 'packages/flutter_gallery_assets/pesto/logo_small.png', - 70.0: 'packages/flutter_gallery_assets/pesto/logo_medium.png' -}; + +const String _kSmallLogoImage = 'packages/flutter_gallery_assets/pesto/logo_small.png'; +const String _kMediumLogoImage = 'packages/flutter_gallery_assets/pesto/logo_medium.png'; final ThemeData _kTheme = new ThemeData( brightness: Brightness.light, @@ -94,20 +92,18 @@ class _PestoDemoState extends State { flexibleSpace: new LayoutBuilder( builder: (BuildContext context, BoxConstraints constraints) { final Size size = constraints.biggest; - double appBarHeight = size.height - statusBarHeight; - double bestHeight = _kLogoImages.keys.lastWhere( - (double height) => appBarHeight >= height - ); + final double appBarHeight = size.height - statusBarHeight; + final String logo = appBarHeight >= 70.0 ? _kMediumLogoImage : _kSmallLogoImage; // Extra padding. Calculated to give about 16px on the bottom for the // `small` logo at its native size, and 30px for the `medium`. - double extraPadding = min(0.19 * appBarHeight + 5.4, 40.0); + final double extraPadding = min(0.19 * appBarHeight + 5.4, 40.0); return new Padding( padding: new EdgeInsets.only( top: statusBarHeight + 0.5 * extraPadding, bottom: extraPadding ), child: new Center( - child: new Image.asset(_kLogoImages[bestHeight], fit: ImageFit.scaleDown) + child: new Image.asset(logo, fit: ImageFit.scaleDown) ) ); } diff --git a/examples/flutter_gallery/test/pesto_test.dart b/examples/flutter_gallery/test/pesto_test.dart index 22f6f4b08a2..e23f9bdc512 100644 --- a/examples/flutter_gallery/test/pesto_test.dart +++ b/examples/flutter_gallery/test/pesto_test.dart @@ -4,7 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:flutter_gallery/main.dart' as flutter_gallery_main; +import 'package:flutter_gallery/gallery/app.dart'; Finder byTooltip(WidgetTester tester, String message) { return find.byWidgetPredicate((Widget widget) { @@ -17,14 +17,13 @@ Finder findNavigationMenuButton(WidgetTester tester) { } void main() { - TestWidgetsFlutterBinding binding = - TestWidgetsFlutterBinding.ensureInitialized(); - if (binding is LiveTestWidgetsFlutterBinding) binding.allowAllFrames = true; + TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized(); + if (binding is LiveTestWidgetsFlutterBinding) + binding.allowAllFrames = true; // Regression test for https://github.com/flutter/flutter/pull/5168 testWidgets('Pesto route management', (WidgetTester tester) async { - flutter_gallery_main - .main(); // builds the app and schedules a frame but doesn't trigger one + await tester.pumpWidget(new GalleryApp()); await tester.pump(); // see https://github.com/flutter/flutter/issues/1865 await tester.pump(); // triggers a frame @@ -52,4 +51,35 @@ void main() { expect(find.text('Flutter Gallery'), findsOneWidget); }); + + // Regression test for https://github.com/flutter/flutter/pull/5168 + testWidgets('Pesto appbar heroics', (WidgetTester tester) async { + await tester.pumpWidget( + // The bug only manifests itself when the screen's orientation is portait + new Center( + child: new SizedBox( + width: 400.0, + height: 800.0, + child: new GalleryApp() + ) + ) + ); + await tester.pump(); // see https://github.com/flutter/flutter/issues/1865 + await tester.pump(); // triggers a frame + + await tester.tap(find.text('Pesto')); + await tester.pump(); // Launch pesto + await tester.pump(const Duration(seconds: 1)); // transition is complete + + await tester.tap(find.text('Pesto Bruchetta')); + await tester.pump(); // Launch the recipe page + await tester.pump(const Duration(seconds: 1)); // transition is complete + + await tester.scroll(find.text('Pesto Bruchetta'), const Offset(0.0, -300.0)); + await tester.pump(); + + Navigator.pop(find.byType(Scaffold).evaluate().single); + await tester.pump(); + await tester.pump(const Duration(seconds: 1)); // transition is complete + }); }