@@ -3220,48 +3220,62 @@ void main() {
32203220 expect (find.text (tooltipText), findsNothing);
32213221 });
32223222
3223- testWidgets ('Escape key dismisses open RawTooltip without moving focus' , (
3224- WidgetTester tester ,
3225- ) async {
3226- final key = GlobalKey <RawTooltipState >();
3227- final focusNode = FocusNode ();
3228- addTearDown (focusNode .dispose);
3223+ testWidgets (
3224+ 'Escape key dismisses hovered RawTooltip even when primaryFocus is on a sibling consuming Escape' ,
3225+ ( WidgetTester tester ) async {
3226+ final key = GlobalKey <RawTooltipState >();
3227+ final siblingFocusNode = FocusNode ();
3228+ addTearDown (siblingFocusNode .dispose);
32293229
3230- await tester.pumpWidget (
3231- Directionality (
3232- textDirection: TextDirection .ltr,
3233- child: Overlay (
3234- initialEntries: < OverlayEntry > [
3235- OverlayEntry (
3236- builder: (BuildContext context) => Center (
3237- child: RawTooltip (
3238- key: key,
3239- semanticsTooltip: tooltipText,
3240- tooltipBuilder: (BuildContext context, Animation <double > animation) =>
3241- const Text (tooltipText),
3242- child: Focus (
3243- focusNode: focusNode,
3244- child: const SizedBox (width: 100.0 , height: 100.0 ),
3245- ),
3230+ await tester.pumpWidget (
3231+ Directionality (
3232+ textDirection: TextDirection .ltr,
3233+ child: Overlay (
3234+ initialEntries: < OverlayEntry > [
3235+ OverlayEntry (
3236+ builder: (BuildContext context) => Column (
3237+ children: < Widget > [
3238+ // Simulates a focused TextField/EditableText or menu whose
3239+ // local Shortcuts/Focus consumes Escape and stops propagation
3240+ // before reaching any ancestor Focus/Shortcuts in WidgetsApp,
3241+ // while primaryFocus is outside RawTooltip.child.
3242+ Focus (
3243+ focusNode: siblingFocusNode,
3244+ onKeyEvent: (FocusNode node, KeyEvent event) {
3245+ if (event.logicalKey == LogicalKeyboardKey .escape) {
3246+ return KeyEventResult .handled;
3247+ }
3248+ return KeyEventResult .ignored;
3249+ },
3250+ child: const SizedBox (width: 100.0 , height: 100.0 ),
3251+ ),
3252+ RawTooltip (
3253+ key: key,
3254+ semanticsTooltip: tooltipText,
3255+ tooltipBuilder: (BuildContext context, Animation <double > animation) =>
3256+ const Text (tooltipText),
3257+ child: const SizedBox (width: 100.0 , height: 100.0 ),
3258+ ),
3259+ ],
32463260 ),
32473261 ),
3248- ) ,
3249- ] ,
3262+ ] ,
3263+ ) ,
32503264 ),
3251- ),
3252- );
3265+ );
32533266
3254- focusNode .requestFocus ();
3255- key.currentState! .ensureTooltipVisible ();
3256- await tester.pumpAndSettle ();
3257- expect (focusNode .hasPrimaryFocus, isTrue);
3258- expect (find.text (tooltipText), findsOneWidget);
3267+ siblingFocusNode .requestFocus ();
3268+ key.currentState! .ensureTooltipVisible ();
3269+ await tester.pumpAndSettle ();
3270+ expect (siblingFocusNode .hasPrimaryFocus, isTrue);
3271+ expect (find.text (tooltipText), findsOneWidget);
32593272
3260- await tester.sendKeyEvent (LogicalKeyboardKey .escape);
3261- await tester.pumpAndSettle ();
3262- expect (find.text (tooltipText), findsNothing);
3263- expect (focusNode.hasPrimaryFocus, isTrue);
3264- });
3273+ await tester.sendKeyEvent (LogicalKeyboardKey .escape);
3274+ await tester.pumpAndSettle ();
3275+ expect (find.text (tooltipText), findsNothing);
3276+ expect (siblingFocusNode.hasPrimaryFocus, isTrue);
3277+ },
3278+ );
32653279}
32663280
32673281Future <void > setWidgetForTooltipMode (
0 commit comments