mirror of
https://github.com/flutter/flutter
synced 2024-10-13 19:52:53 +00:00
Add missing margin to SnackBarAction (#67167)
This commit is contained in:
parent
1fb94fb894
commit
e8343c0ec4
|
@ -427,6 +427,8 @@ class _SnackBarState extends State<SnackBar> {
|
|||
final EdgeInsetsGeometry padding = widget.padding
|
||||
?? EdgeInsetsDirectional.only(start: horizontalPadding, end: widget.action != null ? 0 : horizontalPadding);
|
||||
|
||||
final double actionHorizontalMargin = (widget.padding?.resolve(TextDirection.ltr).right ?? horizontalPadding) / 2;
|
||||
|
||||
final CurvedAnimation heightAnimation = CurvedAnimation(parent: widget.animation!, curve: _snackBarHeightCurve);
|
||||
final CurvedAnimation fadeInAnimation = CurvedAnimation(parent: widget.animation!, curve: _snackBarFadeInCurve);
|
||||
final CurvedAnimation fadeOutAnimation = CurvedAnimation(
|
||||
|
@ -450,14 +452,17 @@ class _SnackBarState extends State<SnackBar> {
|
|||
),
|
||||
),
|
||||
if (widget.action != null)
|
||||
TextButtonTheme(
|
||||
data: TextButtonThemeData(
|
||||
style: TextButton.styleFrom(
|
||||
primary: buttonColor,
|
||||
padding: EdgeInsets.symmetric(horizontal: horizontalPadding),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: actionHorizontalMargin),
|
||||
child: TextButtonTheme(
|
||||
data: TextButtonThemeData(
|
||||
style: TextButton.styleFrom(
|
||||
primary: buttonColor,
|
||||
padding: EdgeInsets.symmetric(horizontal: horizontalPadding),
|
||||
),
|
||||
),
|
||||
child: widget.action!,
|
||||
),
|
||||
child: widget.action!,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
@ -972,8 +972,8 @@ void main() {
|
|||
|
||||
expect(textBottomLeft.dx - snackBarBottomLeft.dx, 24.0 + 10.0); // margin + left padding
|
||||
expect(snackBarBottomLeft.dy - textBottomLeft.dy, 17.0 + 40.0); // margin + bottom padding
|
||||
expect(actionTextBottomLeft.dx - textBottomRight.dx, 24.0);
|
||||
expect(snackBarBottomRight.dx - actionTextBottomRight.dx, 24.0 + 30.0); // margin + right padding
|
||||
expect(actionTextBottomLeft.dx - textBottomRight.dx, 24.0 + 12.0); // action padding + margin
|
||||
expect(snackBarBottomRight.dx - actionTextBottomRight.dx, 24.0 + 12.0 + 30.0); // action (padding + margin) + right padding
|
||||
expect(snackBarBottomRight.dy - actionTextBottomRight.dy, 17.0 + 40.0); // margin + bottom padding
|
||||
});
|
||||
|
||||
|
@ -1027,8 +1027,8 @@ void main() {
|
|||
|
||||
expect(textBottomLeft.dx - snackBarBottomLeft.dx, 24.0 + 10.0); // margin + left padding
|
||||
expect(snackBarBottomLeft.dy - textBottomLeft.dy, 17.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(actionTextBottomLeft.dx - textBottomRight.dx, 24.0 + 12.0); // action padding + margin
|
||||
expect(snackBarBottomRight.dx - actionTextBottomRight.dx, 24.0 + 12.0 + 30.0); // action (padding + margin) + right padding
|
||||
expect(snackBarBottomRight.dy - actionTextBottomRight.dy, 17.0); // margin (with no bottom padding)
|
||||
});
|
||||
|
||||
|
@ -1132,8 +1132,8 @@ void main() {
|
|||
|
||||
expect(textBottomLeft.dx - snackBarBottomLeft.dx, 31.0 + 10.0); // margin + left padding
|
||||
expect(snackBarBottomLeft.dy - textBottomLeft.dy, 27.0); // margin (with no bottom padding)
|
||||
expect(actionTextBottomLeft.dx - textBottomRight.dx, 16.0);
|
||||
expect(snackBarBottomRight.dx - actionTextBottomRight.dx, 31.0 + 30.0); // margin + right padding
|
||||
expect(actionTextBottomLeft.dx - textBottomRight.dx, 16.0 + 8.0); // action padding + margin
|
||||
expect(snackBarBottomRight.dx - actionTextBottomRight.dx, 31.0 + 30.0 + 8.0); // margin + right (padding + margin)
|
||||
expect(snackBarBottomRight.dy - actionTextBottomRight.dy, 27.0); // margin (with no bottom padding)
|
||||
});
|
||||
|
||||
|
@ -1190,8 +1190,8 @@ void main() {
|
|||
|
||||
expect(textBottomLeft.dx - snackBarBottomLeft.dx, 31.0 + 10.0); // margin + left padding
|
||||
expect(snackBarBottomLeft.dy - textBottomLeft.dy, 27.0); // margin (with no bottom padding)
|
||||
expect(actionTextBottomLeft.dx - textBottomRight.dx, 16.0);
|
||||
expect(snackBarBottomRight.dx - actionTextBottomRight.dx, 31.0 + 30.0); // margin + right padding
|
||||
expect(actionTextBottomLeft.dx - textBottomRight.dx, 16.0 + 8.0); // action (margin + padding)
|
||||
expect(snackBarBottomRight.dx - actionTextBottomRight.dx, 31.0 + 30.0 + 8.0); // margin + right (padding + margin)
|
||||
expect(snackBarBottomRight.dy - actionTextBottomRight.dy, 27.0); // margin (with no bottom padding)
|
||||
});
|
||||
|
||||
|
@ -1942,6 +1942,79 @@ void main() {
|
|||
expect(snackBarBottomRight.dy, equals(fabTopRight.dy));
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'SnackBar has correct end padding when it contains an action with fixed behavior',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
Scaffold.of(context)!.showSnackBar(SnackBar(
|
||||
content: const Text('Some content'),
|
||||
behavior: SnackBarBehavior.fixed,
|
||||
action: SnackBarAction(
|
||||
label: 'ACTION',
|
||||
onPressed: () {},
|
||||
),
|
||||
));
|
||||
},
|
||||
child: const Text('X'),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.text('X'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final Offset snackBarTopRight = tester.getTopRight(find.byType(SnackBar));
|
||||
final Offset actionTopRight = tester.getTopRight(find.byType(SnackBarAction));
|
||||
|
||||
expect(snackBarTopRight.dx - actionTopRight.dx, 12.0);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'SnackBar has correct end padding when it contains an action with floating behavior',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
Scaffold.of(context)!.showSnackBar(SnackBar(
|
||||
content: const Text('Some content'),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
action: SnackBarAction(
|
||||
label: 'ACTION',
|
||||
onPressed: () {},
|
||||
),
|
||||
));
|
||||
},
|
||||
child: const Text('X'),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.text('X'));
|
||||
await tester.pumpAndSettle();
|
||||
final Offset snackBarTopRight = tester.getTopRight(find.byType(SnackBar));
|
||||
final Offset actionTopRight = tester.getTopRight(find.byType(SnackBarAction));
|
||||
|
||||
expect(snackBarTopRight.dx - actionTopRight.dx, 8.0 + 15.0); // button margin + horizontal scaffold outside margin
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('SnackBars hero across transitions when using ScaffoldMessenger', (WidgetTester tester) async {
|
||||
|
|
Loading…
Reference in a new issue