diff --git a/packages/flutter/lib/src/material/scaffold.dart b/packages/flutter/lib/src/material/scaffold.dart index 7c1e04163f..57f0d07741 100644 --- a/packages/flutter/lib/src/material/scaffold.dart +++ b/packages/flutter/lib/src/material/scaffold.dart @@ -886,6 +886,7 @@ class ScaffoldState extends State with TickerProviderStateMixin { } if (_snackBars.isNotEmpty) { + final bool removeBottomPadding = widget.persistentFooterButtons != null || widget.bottomNavigationBar != null; _addIfNonNull( children, _snackBars.first._widget, @@ -893,7 +894,7 @@ class ScaffoldState extends State with TickerProviderStateMixin { removeLeftPadding: false, removeTopPadding: true, removeRightPadding: false, - removeBottomPadding: false, + removeBottomPadding: removeBottomPadding, ); } diff --git a/packages/flutter/test/material/snack_bar_test.dart b/packages/flutter/test/material/snack_bar_test.dart index f69996931e..a05542d48b 100644 --- a/packages/flutter/test/material/snack_bar_test.dart +++ b/packages/flutter/test/material/snack_bar_test.dart @@ -347,6 +347,63 @@ void main() { expect(snackBarBottomRight.dy - actionTextBottomRight.dy, 14.0 + 40.0); // margin + bottom padding }); + testWidgets('SnackBar is positioned above BottomNavigationBar', (WidgetTester tester) async { + await tester.pumpWidget(new MaterialApp( + home: new MediaQuery( + data: const MediaQueryData( + padding: const EdgeInsets.only( + left: 10.0, + top: 20.0, + right: 30.0, + bottom: 40.0, + ), + ), + child: new Scaffold( + bottomNavigationBar: new BottomNavigationBar( + items: [ + const BottomNavigationBarItem(icon: const Icon(Icons.favorite), title: const Text('Animutation')), + const BottomNavigationBarItem(icon: const Icon(Icons.block), title: const Text('Zombo.com')), + ], + ), + body: new Builder( + builder: (BuildContext context) { + return new GestureDetector( + onTap: () { + Scaffold.of(context).showSnackBar(new SnackBar( + content: const Text('I am a snack bar.'), + duration: const Duration(seconds: 2), + action: new SnackBarAction(label: 'ACTION', onPressed: () {}) + )); + }, + child: const Text('X') + ); + } + ), + ), + ), + )); + await tester.tap(find.text('X')); + await tester.pump(); // start animation + await tester.pump(const Duration(milliseconds: 750)); + + final RenderBox textBox = tester.firstRenderObject(find.text('I am a snack bar.')); + final RenderBox actionTextBox = tester.firstRenderObject(find.text('ACTION')); + final RenderBox snackBarBox = tester.firstRenderObject(find.byType(SnackBar)); + + final Offset textBottomLeft = textBox.localToGlobal(textBox.size.bottomLeft(Offset.zero)); + final Offset textBottomRight = textBox.localToGlobal(textBox.size.bottomRight(Offset.zero)); + final Offset actionTextBottomLeft = actionTextBox.localToGlobal(actionTextBox.size.bottomLeft(Offset.zero)); + final Offset actionTextBottomRight = actionTextBox.localToGlobal(actionTextBox.size.bottomRight(Offset.zero)); + final Offset snackBarBottomLeft = snackBarBox.localToGlobal(snackBarBox.size.bottomLeft(Offset.zero)); + final Offset snackBarBottomRight = snackBarBox.localToGlobal(snackBarBox.size.bottomRight(Offset.zero)); + + expect(textBottomLeft.dx - snackBarBottomLeft.dx, 24.0 + 10.0); // margin + left padding + expect(snackBarBottomLeft.dy - textBottomLeft.dy, 14.0); // margin (with no bottom padding) + expect(actionTextBottomLeft.dx - textBottomRight.dx, 24.0); + expect(snackBarBottomRight.dx - actionTextBottomRight.dx, 24.0 + 30.0); // margin + right padding + expect(snackBarBottomRight.dy - actionTextBottomRight.dy, 14.0); // margin (with no bottom padding) + }); + testWidgets('SnackBarClosedReason', (WidgetTester tester) async { final GlobalKey scaffoldKey = new GlobalKey(); bool actionPressed = false;