Unverified Commit 882be89e authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

Improved bottom media padding for SnackBars (#14396)

In a scaffold, snackbars are positioned above the BottomNavigationBar
and/or PersistentBottomButtons, if present. In such cases, they should
not apply bottom media padding to their widget sub-tree.
parent 3fd737c8
...@@ -886,6 +886,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin { ...@@ -886,6 +886,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
} }
if (_snackBars.isNotEmpty) { if (_snackBars.isNotEmpty) {
final bool removeBottomPadding = widget.persistentFooterButtons != null || widget.bottomNavigationBar != null;
_addIfNonNull( _addIfNonNull(
children, children,
_snackBars.first._widget, _snackBars.first._widget,
...@@ -893,7 +894,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin { ...@@ -893,7 +894,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
removeLeftPadding: false, removeLeftPadding: false,
removeTopPadding: true, removeTopPadding: true,
removeRightPadding: false, removeRightPadding: false,
removeBottomPadding: false, removeBottomPadding: removeBottomPadding,
); );
} }
......
...@@ -347,6 +347,63 @@ void main() { ...@@ -347,6 +347,63 @@ void main() {
expect(snackBarBottomRight.dy - actionTextBottomRight.dy, 14.0 + 40.0); // margin + bottom padding 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: <BottomNavigationBarItem>[
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 { testWidgets('SnackBarClosedReason', (WidgetTester tester) async {
final GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>(); final GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>();
bool actionPressed = false; bool actionPressed = false;
......
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