File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import 'colors.dart';
1111import 'icon_button.dart' ;
1212import 'icons.dart' ;
1313import 'material.dart' ;
14+ import 'material_localizations.dart' ;
1415import 'material_state.dart' ;
1516import 'scaffold.dart' ;
1617import 'snack_bar_theme.dart' ;
@@ -656,6 +657,7 @@ class _SnackBarState extends State<SnackBar> {
656657 iconSize: 24.0 ,
657658 color: widget.closeIconColor ?? snackBarTheme.closeIconColor ?? defaults.closeIconColor,
658659 onPressed: () => ScaffoldMessenger .of (context).hideCurrentSnackBar (reason: SnackBarClosedReason .dismiss),
660+ tooltip: MaterialLocalizations .of (context).closeButtonTooltip,
659661 )
660662 : null ;
661663
Original file line number Diff line number Diff line change @@ -3243,6 +3243,40 @@ void main() {
32433243 'snack_bar.goldenTest.floatingWithActionWithIcon.png' ));
32443244 });
32453245
3246+ testWidgets ('SnackBar has tooltip for Close Button' , (WidgetTester tester) async {
3247+ // Regression test for https://github.com/flutter/flutter/issues/143793
3248+ await tester.pumpWidget (MaterialApp (
3249+ theme: ThemeData (useMaterial3: false ),
3250+ debugShowCheckedModeBanner: false , // https://github.com/flutter/flutter/issues/143616
3251+ home: const Scaffold (
3252+ bottomSheet: SizedBox (
3253+ width: 200 ,
3254+ height: 50 ,
3255+ child: ColoredBox (
3256+ color: Colors .pink,
3257+ ),
3258+ ),
3259+ ),
3260+ ));
3261+
3262+ final ScaffoldMessengerState scaffoldMessengerState = tester.state (find.byType (ScaffoldMessenger ));
3263+ scaffoldMessengerState.showSnackBar (
3264+ SnackBar (
3265+ content: const Text ('Snackbar with close button' ),
3266+ duration: const Duration (days: 365 ),
3267+ action: SnackBarAction (label: 'ACTION' , onPressed: () {}),
3268+ behavior: SnackBarBehavior .floating,
3269+ showCloseIcon: true ,
3270+ ),
3271+ );
3272+ await tester.pumpAndSettle (); // Have the SnackBar fully animate in.
3273+
3274+ expect (
3275+ find.byTooltip (MaterialLocalizations .of (scaffoldMessengerState.context).closeButtonLabel),
3276+ findsOneWidget
3277+ );
3278+ });
3279+
32463280 testWidgets ('Material2 - Fixed width snackbar can display optional icon' , (WidgetTester tester) async {
32473281 await tester.pumpWidget (MaterialApp (
32483282 theme: ThemeData (useMaterial3: false ),
You can’t perform that action at this time.
0 commit comments