From 71021b4706c0311648087a15d6c9015de5a660ba Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 7 Dec 2017 12:59:26 -0800 Subject: [PATCH] Use greater of viewInsets, padding for Scaffold bottom padding (#13423) Scaffold bottom padding now applies the maximum of window viewInsets.bottom (typically used for iOS safe areas) and padding.bottom (typically used for keyboard height). --- .../flutter/lib/src/material/scaffold.dart | 5 +-- .../flutter/test/material/scaffold_test.dart | 35 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/material/scaffold.dart b/packages/flutter/lib/src/material/scaffold.dart index 0e49b6ad1a..3dc181dd6f 100644 --- a/packages/flutter/lib/src/material/scaffold.dart +++ b/packages/flutter/lib/src/material/scaffold.dart @@ -834,6 +834,7 @@ class ScaffoldState extends State with TickerProviderStateMixin { assert(debugCheckHasMediaQuery(context)); assert(debugCheckHasDirectionality(context)); final EdgeInsets padding = MediaQuery.of(context).padding; + final EdgeInsets viewInsets = MediaQuery.of(context).viewInsets; final ThemeData themeData = Theme.of(context); final TextDirection textDirection = Directionality.of(context); @@ -1038,7 +1039,7 @@ class ScaffoldState extends State with TickerProviderStateMixin { children: children, delegate: new _ScaffoldLayout( statusBarHeight: padding.top, - bottomPadding: widget.resizeToAvoidBottomPadding ? padding.bottom : 0.0, + bottomPadding: widget.resizeToAvoidBottomPadding ? math.max(padding.bottom, viewInsets.bottom) : 0.0, endPadding: endPadding, textDirection: textDirection, ), @@ -1157,4 +1158,4 @@ class _ScaffoldScope extends InheritedWidget { bool updateShouldNotify(_ScaffoldScope oldWidget) { return hasDrawer != oldWidget.hasDrawer; } -} \ No newline at end of file +} diff --git a/packages/flutter/test/material/scaffold_test.dart b/packages/flutter/test/material/scaffold_test.dart index 8e2f93d68c..d7a3673966 100644 --- a/packages/flutter/test/material/scaffold_test.dart +++ b/packages/flutter/test/material/scaffold_test.dart @@ -59,6 +59,41 @@ void main() { expect(bodyBox.size, equals(const Size(800.0, 544.0))); }); + testWidgets('Scaffold bottom padding is the greater of window padding or view inset', (WidgetTester tester) async { + final Key bodyKey = new UniqueKey(); + await tester.pumpWidget(new Directionality( + textDirection: TextDirection.ltr, + child: new MediaQuery( + data: const MediaQueryData( + padding: const EdgeInsets.only(bottom: 50.0), + viewInsets: const EdgeInsets.only(bottom: 100.0), + ), + child: new Scaffold( + body: new Container(key: bodyKey), + ), + ), + )); + + final RenderBox bodyBox = tester.renderObject(find.byKey(bodyKey)); + expect(bodyBox.size, equals(const Size(800.0, 500.0))); + + await tester.pumpWidget(new Directionality( + textDirection: TextDirection.ltr, + child: new MediaQuery( + data: const MediaQueryData( + padding: const EdgeInsets.only(bottom: 200.0), + viewInsets: const EdgeInsets.only(bottom: 100.0), + ), + child: new Scaffold( + body: new Container(key: bodyKey), + ), + ), + )); + + expect(bodyBox.size, equals(const Size(800.0, 400.0))); + }); + + testWidgets('Scaffold large bottom padding test', (WidgetTester tester) async { final Key bodyKey = new UniqueKey(); await tester.pumpWidget(new Directionality(