Commit 96ec30b8 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Fix Pesto appbar heroics (#5447)

parent ade895de
...@@ -9,11 +9,9 @@ import 'package:flutter/material.dart'; ...@@ -9,11 +9,9 @@ import 'package:flutter/material.dart';
const String _kUserName = 'Jonathan'; const String _kUserName = 'Jonathan';
const String _kUserEmail = 'jonathan@example.com'; const String _kUserEmail = 'jonathan@example.com';
const String _kUserImage = 'packages/flutter_gallery_assets/pesto/avatar.jpg'; 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<double, String> _kLogoImages = <double, String>{ const String _kSmallLogoImage = 'packages/flutter_gallery_assets/pesto/logo_small.png';
0.0: 'packages/flutter_gallery_assets/pesto/logo_small.png', const String _kMediumLogoImage = 'packages/flutter_gallery_assets/pesto/logo_medium.png';
70.0: 'packages/flutter_gallery_assets/pesto/logo_medium.png'
};
final ThemeData _kTheme = new ThemeData( final ThemeData _kTheme = new ThemeData(
brightness: Brightness.light, brightness: Brightness.light,
...@@ -94,20 +92,18 @@ class _PestoDemoState extends State<PestoDemo> { ...@@ -94,20 +92,18 @@ class _PestoDemoState extends State<PestoDemo> {
flexibleSpace: new LayoutBuilder( flexibleSpace: new LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) { builder: (BuildContext context, BoxConstraints constraints) {
final Size size = constraints.biggest; final Size size = constraints.biggest;
double appBarHeight = size.height - statusBarHeight; final double appBarHeight = size.height - statusBarHeight;
double bestHeight = _kLogoImages.keys.lastWhere( final String logo = appBarHeight >= 70.0 ? _kMediumLogoImage : _kSmallLogoImage;
(double height) => appBarHeight >= height
);
// Extra padding. Calculated to give about 16px on the bottom for the // Extra padding. Calculated to give about 16px on the bottom for the
// `small` logo at its native size, and 30px for the `medium`. // `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( return new Padding(
padding: new EdgeInsets.only( padding: new EdgeInsets.only(
top: statusBarHeight + 0.5 * extraPadding, top: statusBarHeight + 0.5 * extraPadding,
bottom: extraPadding bottom: extraPadding
), ),
child: new Center( child: new Center(
child: new Image.asset(_kLogoImages[bestHeight], fit: ImageFit.scaleDown) child: new Image.asset(logo, fit: ImageFit.scaleDown)
) )
); );
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.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) { Finder byTooltip(WidgetTester tester, String message) {
return find.byWidgetPredicate((Widget widget) { return find.byWidgetPredicate((Widget widget) {
...@@ -17,14 +17,13 @@ Finder findNavigationMenuButton(WidgetTester tester) { ...@@ -17,14 +17,13 @@ Finder findNavigationMenuButton(WidgetTester tester) {
} }
void main() { void main() {
TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
TestWidgetsFlutterBinding.ensureInitialized(); if (binding is LiveTestWidgetsFlutterBinding)
if (binding is LiveTestWidgetsFlutterBinding) binding.allowAllFrames = true; binding.allowAllFrames = true;
// Regression test for https://github.com/flutter/flutter/pull/5168 // Regression test for https://github.com/flutter/flutter/pull/5168
testWidgets('Pesto route management', (WidgetTester tester) async { testWidgets('Pesto route management', (WidgetTester tester) async {
flutter_gallery_main await tester.pumpWidget(new GalleryApp());
.main(); // builds the app and schedules a frame but doesn't trigger one
await tester.pump(); // see https://github.com/flutter/flutter/issues/1865 await tester.pump(); // see https://github.com/flutter/flutter/issues/1865
await tester.pump(); // triggers a frame await tester.pump(); // triggers a frame
...@@ -52,4 +51,35 @@ void main() { ...@@ -52,4 +51,35 @@ void main() {
expect(find.text('Flutter Gallery'), findsOneWidget); 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
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment