Unverified Commit 813be533 authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

Apply media padding to snackbar contents (#13623)

Applies any additional bottom, left, and right media padding inside the
snackbar, if present. This accounts for the iPhone X home indicator
widget and horizontal padding for the sensor housing notch in landscape
orientation.
parent a556ad09
...@@ -893,7 +893,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin { ...@@ -893,7 +893,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
removeLeftPadding: false, removeLeftPadding: false,
removeTopPadding: true, removeTopPadding: true,
removeRightPadding: false, removeRightPadding: false,
removeBottomPadding: widget.resizeToAvoidBottomPadding, removeBottomPadding: false,
); );
} }
......
...@@ -241,9 +241,12 @@ class SnackBar extends StatelessWidget { ...@@ -241,9 +241,12 @@ class SnackBar extends StatelessWidget {
data: darkTheme, data: darkTheme,
child: new FadeTransition( child: new FadeTransition(
opacity: fadeAnimation, opacity: fadeAnimation,
child: new Row( child: new SafeArea(
children: children, top: false,
crossAxisAlignment: CrossAxisAlignment.center, child: new Row(
children: children,
crossAxisAlignment: CrossAxisAlignment.center,
),
), ),
), ),
), ),
......
...@@ -298,22 +298,32 @@ void main() { ...@@ -298,22 +298,32 @@ void main() {
testWidgets('SnackBar button text alignment', (WidgetTester tester) async { testWidgets('SnackBar button text alignment', (WidgetTester tester) async {
await tester.pumpWidget(new MaterialApp( await tester.pumpWidget(new MaterialApp(
home: new Scaffold( home: new MediaQuery(
body: new Builder( data: const MediaQueryData(
builder: (BuildContext context) { padding: const EdgeInsets.only(
return new GestureDetector( left: 10.0,
onTap: () { top: 20.0,
Scaffold.of(context).showSnackBar(new SnackBar( right: 30.0,
content: const Text('I am a snack bar.'), bottom: 40.0,
duration: const Duration(seconds: 2), ),
action: new SnackBarAction(label: 'ACTION', onPressed: () {}) ),
)); child: new Scaffold(
}, body: new Builder(
child: const Text('X') 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.tap(find.text('X'));
await tester.pump(); // start animation await tester.pump(); // start animation
...@@ -330,9 +340,11 @@ void main() { ...@@ -330,9 +340,11 @@ void main() {
final Offset snackBarBottomLeft = snackBarBox.localToGlobal(snackBarBox.size.bottomLeft(Offset.zero)); final Offset snackBarBottomLeft = snackBarBox.localToGlobal(snackBarBox.size.bottomLeft(Offset.zero));
final Offset snackBarBottomRight = snackBarBox.localToGlobal(snackBarBox.size.bottomRight(Offset.zero)); final Offset snackBarBottomRight = snackBarBox.localToGlobal(snackBarBox.size.bottomRight(Offset.zero));
expect(textBottomLeft.dx - snackBarBottomLeft.dx, 24.0); expect(textBottomLeft.dx - snackBarBottomLeft.dx, 24.0 + 10.0); // margin + left padding
expect(snackBarBottomLeft.dy - textBottomLeft.dy, 14.0 + 40.0); // margin + bottom padding
expect(actionTextBottomLeft.dx - textBottomRight.dx, 24.0); expect(actionTextBottomLeft.dx - textBottomRight.dx, 24.0);
expect(snackBarBottomRight.dx - actionTextBottomRight.dx, 24.0); expect(snackBarBottomRight.dx - actionTextBottomRight.dx, 24.0 + 30.0); // margin + right padding
expect(snackBarBottomRight.dy - actionTextBottomRight.dy, 14.0 + 40.0); // margin + bottom padding
}); });
testWidgets('SnackBarClosedReason', (WidgetTester tester) async { testWidgets('SnackBarClosedReason', (WidgetTester tester) async {
......
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