From 55f48f72c992c2b3a845ed8894bf2dab5bc06461 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Mon, 26 Sep 2016 14:02:01 -0700 Subject: [PATCH] Persistent bottom sheet should not overlap app bar (#6076) The spec forbids persistent bottom sheets from overlapping the app bar. There are also some fancy scroll-linked effects that we're supposed to do with persistent bottom sheets, but those will need to wait for another patch. Fixes #5143 --- .../flutter/lib/src/material/scaffold.dart | 2 +- .../flutter/test/material/scaffold_test.dart | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/scaffold.dart b/packages/flutter/lib/src/material/scaffold.dart index d96673eb69..f99618947f 100644 --- a/packages/flutter/lib/src/material/scaffold.dart +++ b/packages/flutter/lib/src/material/scaffold.dart @@ -120,7 +120,7 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate { Size snackBarSize = Size.zero; if (hasChild(_ScaffoldSlot.bottomSheet)) { - bottomSheetSize = layoutChild(_ScaffoldSlot.bottomSheet, fullWidthConstraints); + bottomSheetSize = layoutChild(_ScaffoldSlot.bottomSheet, fullWidthConstraints.copyWith(maxHeight: contentBottom - contentTop)); positionChild(_ScaffoldSlot.bottomSheet, new Offset((size.width - bottomSheetSize.width) / 2.0, bottom - bottomSheetSize.height)); } diff --git a/packages/flutter/test/material/scaffold_test.dart b/packages/flutter/test/material/scaffold_test.dart index eb6a8ff4d6..dbe74c0c65 100644 --- a/packages/flutter/test/material/scaffold_test.dart +++ b/packages/flutter/test/material/scaffold_test.dart @@ -196,4 +196,46 @@ void main() { await tester.pump(new Duration(seconds: 1)); expect(scrollableKey.currentState.scrollOffset, equals(500.0)); }); + + testWidgets('Bottom sheet cannot overlap app bar', (WidgetTester tester) async { + Key sheetKey = new UniqueKey(); + + await tester.pumpWidget( + new MaterialApp( + theme: new ThemeData(platform: TargetPlatform.android), + home: new Scaffold( + appBar: new AppBar( + title: new Text('Title') + ), + body: new Builder( + builder: (BuildContext context) { + return new GestureDetector( + onTap: () { + Scaffold.of(context).showBottomSheet((BuildContext context) { + return new Container( + key: sheetKey, + decoration: new BoxDecoration(backgroundColor: Colors.blue[500]) + ); + }); + }, + child: new Text('X') + ); + } + ) + ) + ) + ); + + await tester.tap(find.text('X')); + await tester.pump(); // start animation + await tester.pump(const Duration(seconds: 1)); + + RenderBox appBarBox = tester.renderObject(find.byType(AppBar)); + RenderBox sheetBox = tester.renderObject(find.byKey(sheetKey)); + + Point appBarBottomRight = appBarBox.localToGlobal(appBarBox.size.bottomRight(Point.origin)); + Point sheetTopRight = sheetBox.localToGlobal(sheetBox.size.topRight(Point.origin)); + + expect(appBarBottomRight, equals(sheetTopRight)); + }); }