diff --git a/packages/flutter/lib/src/material/scaffold.dart b/packages/flutter/lib/src/material/scaffold.dart index 0f8428f0fe..e77630eff2 100644 --- a/packages/flutter/lib/src/material/scaffold.dart +++ b/packages/flutter/lib/src/material/scaffold.dart @@ -48,7 +48,7 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate { @override void performLayout(Size size) { - BoxConstraints looseConstraints = new BoxConstraints.loose(size); + final BoxConstraints looseConstraints = new BoxConstraints.loose(size); // This part of the layout has the same effect as putting the app bar and // body in a column and making the body flexible. What's different is that @@ -56,8 +56,8 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate { // so the app bar's shadow is drawn on top of the body. final BoxConstraints fullWidthConstraints = looseConstraints.tighten(width: size.width); + final double bottom = math.max(0.0, size.height - padding.bottom); double contentTop = 0.0; - double bottom = size.height - padding.bottom; double contentBottom = bottom; if (hasChild(_ScaffoldSlot.appBar)) { @@ -78,10 +78,9 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate { } if (hasChild(_ScaffoldSlot.body)) { - final double bodyHeight = contentBottom - contentTop; final BoxConstraints bodyConstraints = new BoxConstraints( maxWidth: fullWidthConstraints.maxWidth, - maxHeight: bodyHeight, + maxHeight: math.max(0.0, contentBottom - contentTop), ); layoutChild(_ScaffoldSlot.body, bodyConstraints); positionChild(_ScaffoldSlot.body, new Offset(0.0, contentTop)); diff --git a/packages/flutter/test/material/scaffold_test.dart b/packages/flutter/test/material/scaffold_test.dart index e168c4d5b1..40ecc8ad75 100644 --- a/packages/flutter/test/material/scaffold_test.dart +++ b/packages/flutter/test/material/scaffold_test.dart @@ -41,6 +41,46 @@ void main() { expect(bodyBox.size, equals(const Size(800.0, 544.0))); }); + testWidgets('Scaffold large bottom padding test', (WidgetTester tester) async { + Key bodyKey = new UniqueKey(); + await tester.pumpWidget(new MediaQuery( + data: new MediaQueryData( + padding: const EdgeInsets.only(bottom: 700.0), + ), + child: new Scaffold( + body: new Container(key: bodyKey), + ), + )); + + RenderBox bodyBox = tester.renderObject(find.byKey(bodyKey)); + expect(bodyBox.size, equals(const Size(800.0, 0.0))); + + await tester.pumpWidget(new MediaQuery( + data: new MediaQueryData( + padding: const EdgeInsets.only(bottom: 500.0), + ), + child: new Scaffold( + body: new Container(key: bodyKey), + ), + )); + + expect(bodyBox.size, equals(const Size(800.0, 100.0))); + + await tester.pumpWidget(new MediaQuery( + data: new MediaQueryData( + padding: const EdgeInsets.only(bottom: 580.0), + ), + child: new Scaffold( + appBar: new AppBar( + title: new Text('Title'), + ), + body: new Container(key: bodyKey), + ), + )); + + expect(bodyBox.size, equals(const Size(800.0, 0.0))); + }); + testWidgets('Floating action animation', (WidgetTester tester) async { await tester.pumpWidget(new Scaffold( floatingActionButton: new FloatingActionButton(