diff --git a/packages/flutter/lib/src/material/snack_bar.dart b/packages/flutter/lib/src/material/snack_bar.dart index b0a466ed8a..4911b7b96c 100644 --- a/packages/flutter/lib/src/material/snack_bar.dart +++ b/packages/flutter/lib/src/material/snack_bar.dart @@ -5,7 +5,6 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; -import 'button_style.dart'; import 'color_scheme.dart'; import 'colors.dart'; import 'icon_button.dart'; @@ -204,10 +203,11 @@ class _SnackBarActionState extends State { } return TextButton( - style: ButtonStyle( - foregroundColor: resolveForegroundColor(), - backgroundColor: resolveBackgroundColor(), - ), + style: TextButton.styleFrom(overlayColor: resolveForegroundColor()) + .copyWith( + foregroundColor: resolveForegroundColor(), + backgroundColor: resolveBackgroundColor(), + ), onPressed: _haveTriggeredAction ? null : _handlePressed, child: Text(widget.label), ); @@ -671,9 +671,6 @@ class _SnackBarState extends State { final double actionHorizontalMargin = (widget.padding?.resolve(TextDirection.ltr).right ?? horizontalPadding) / 2; final double iconHorizontalMargin = (widget.padding?.resolve(TextDirection.ltr).right ?? horizontalPadding) / 12.0; - - - final IconButton? iconButton = showCloseIcon ? IconButton( icon: const Icon(Icons.close), diff --git a/packages/flutter/test/material/snack_bar_test.dart b/packages/flutter/test/material/snack_bar_test.dart index 105d197d7c..703ee43459 100644 --- a/packages/flutter/test/material/snack_bar_test.dart +++ b/packages/flutter/test/material/snack_bar_test.dart @@ -4045,6 +4045,39 @@ testWidgets('SnackBarAction backgroundColor works as a Color', (WidgetTester tes expect(completer.isCompleted, false); }); + + testWidgets('Action text button uses correct overlay color', (WidgetTester tester) async { + final ThemeData theme = ThemeData(); + await tester.pumpWidget(MaterialApp( + theme: theme, + home: Scaffold( + body: Builder( + builder: (BuildContext context) { + return GestureDetector( + onTap: () { + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + content: const Text('I am a snack bar.'), + action: SnackBarAction(label: 'ACTION', onPressed: () { }), + )); + }, + child: const Text('X'), + ); + }, + ), + ), + )); + + await tester.tap(find.text('X')); + await tester.pumpAndSettle(); + + final ButtonStyle? actionButtonStyle = tester.widget( + find.widgetWithText(TextButton, 'ACTION'), + ).style; + expect( + actionButtonStyle?.overlayColor?.resolve({MaterialState.hovered}), + theme.colorScheme.inversePrimary.withOpacity(0.08), + ); + }); } /// Start test for "SnackBar dismiss test".