@@ -420,7 +420,7 @@ void main() {
420420 expect (find.text ('b' ), findsOneWidget);
421421 });
422422
423- testWidgets ('Adding a new FocusScope attaches the child it to its parent.' , (WidgetTester tester) async {
423+ testWidgets ('Adding a new FocusScope attaches the child to its parent.' , (WidgetTester tester) async {
424424 final GlobalKey <TestFocusState > keyA = GlobalKey ();
425425 final FocusScopeNode parentFocusScope = FocusScopeNode (debugLabel: 'Parent Scope Node' );
426426 final FocusScopeNode childFocusScope = FocusScopeNode (debugLabel: 'Child Scope Node' );
@@ -540,24 +540,24 @@ void main() {
540540
541541 await tester.pumpWidget (
542542 FocusScope .withExternalFocusNode (
543- focusScopeNode: topNode,
544- child: Column (
545- children: < Widget > [
546- FocusScope .withExternalFocusNode (
547- focusScopeNode: parentNode,
548- child: const SizedBox (),
543+ focusScopeNode: topNode,
544+ child: Column (
545+ children: < Widget > [
546+ FocusScope .withExternalFocusNode (
547+ focusScopeNode: parentNode,
548+ child: const SizedBox (),
549+ ),
550+ FocusScope .withExternalFocusNode (
551+ focusScopeNode: childNode,
552+ parentNode: parentNode,
553+ child: const Focus (
554+ autofocus: true ,
555+ child: SizedBox (),
549556 ),
550- FocusScope .withExternalFocusNode (
551- focusScopeNode: childNode,
552- parentNode: parentNode,
553- child: const Focus (
554- autofocus: true ,
555- child: SizedBox (),
556- ),
557- )
558- ],
559- ),
557+ )
558+ ],
560559 ),
560+ ),
561561 );
562562 await tester.pump ();
563563
@@ -568,27 +568,27 @@ void main() {
568568 // Check that inserting a Focus in between doesn't reparent the child.
569569 await tester.pumpWidget (
570570 FocusScope .withExternalFocusNode (
571- focusScopeNode: topNode,
572- child: Column (
573- children: < Widget > [
574- FocusScope .withExternalFocusNode (
575- focusScopeNode: parentNode,
576- child: const SizedBox (),
577- ),
578- FocusScope .withExternalFocusNode (
579- focusScopeNode: insertedNode,
580- child: FocusScope .withExternalFocusNode (
581- focusScopeNode: childNode,
582- parentNode: parentNode,
583- child: const Focus (
571+ focusScopeNode: topNode,
572+ child: Column (
573+ children: < Widget > [
574+ FocusScope .withExternalFocusNode (
575+ focusScopeNode: parentNode,
576+ child: const SizedBox (),
577+ ),
578+ FocusScope .withExternalFocusNode (
579+ focusScopeNode: insertedNode,
580+ child: FocusScope .withExternalFocusNode (
581+ focusScopeNode: childNode,
582+ parentNode: parentNode,
583+ child: const Focus (
584584 autofocus: true ,
585585 child: SizedBox (),
586586 ),
587- ),
588- )
589- ],
590- ),
587+ ),
588+ )
589+ ],
591590 ),
591+ ),
592592 );
593593 await tester.pump ();
594594
@@ -1673,6 +1673,7 @@ void main() {
16731673 await pumpTest (traverseScope1: true );
16741674 expect (scope1.traversalDescendants, equals (< FocusNode > [focus2, focus1, scope2]));
16751675 });
1676+
16761677 testWidgets ('descendantsAreFocusable works as expected.' , (WidgetTester tester) async {
16771678 final GlobalKey key1 = GlobalKey (debugLabel: '1' );
16781679 final GlobalKey key2 = GlobalKey (debugLabel: '2' );
@@ -1756,13 +1757,11 @@ void main() {
17561757 final GlobalKey key1 = GlobalKey (debugLabel: '1' );
17571758 final FocusNode focusNode = FocusNode ();
17581759 bool ? keyEventHandled;
1759- // ignore: prefer_function_declarations_over_variables
1760- final FocusOnKeyCallback handleCallback = (FocusNode node, RawKeyEvent event) {
1760+ KeyEventResult handleCallback (FocusNode node, RawKeyEvent event) {
17611761 keyEventHandled = true ;
17621762 return KeyEventResult .handled;
1763- };
1764- // ignore: prefer_function_declarations_over_variables
1765- final FocusOnKeyCallback ignoreCallback = (FocusNode node, RawKeyEvent event) => KeyEventResult .ignored;
1763+ }
1764+ KeyEventResult ignoreCallback (FocusNode node, RawKeyEvent event) => KeyEventResult .ignored;
17661765 Focus focusWidget = Focus (
17671766 onKey: ignoreCallback, // This one does nothing.
17681767 focusNode: focusNode,
@@ -1807,13 +1806,11 @@ void main() {
18071806 final GlobalKey key1 = GlobalKey (debugLabel: '1' );
18081807 final FocusNode focusNode = FocusNode ();
18091808 bool ? keyEventHandled;
1810- // ignore: prefer_function_declarations_over_variables
1811- final FocusOnKeyEventCallback handleEventCallback = (FocusNode node, KeyEvent event) {
1809+ KeyEventResult handleEventCallback (FocusNode node, KeyEvent event) {
18121810 keyEventHandled = true ;
18131811 return KeyEventResult .handled;
1814- };
1815- // ignore: prefer_function_declarations_over_variables
1816- final FocusOnKeyEventCallback ignoreEventCallback = (FocusNode node, KeyEvent event) => KeyEventResult .ignored;
1812+ }
1813+ KeyEventResult ignoreEventCallback (FocusNode node, KeyEvent event) => KeyEventResult .ignored;
18171814 Focus focusWidget = Focus (
18181815 onKeyEvent: ignoreEventCallback, // This one does nothing.
18191816 focusNode: focusNode,
@@ -1858,20 +1855,16 @@ void main() {
18581855 final GlobalKey key1 = GlobalKey (debugLabel: '1' );
18591856 final FocusNode focusNode = FocusNode ();
18601857 bool ? keyEventHandled;
1861- // ignore: prefer_function_declarations_over_variables
1862- final FocusOnKeyCallback handleCallback = (FocusNode node, RawKeyEvent event) {
1858+ KeyEventResult handleCallback (FocusNode node, RawKeyEvent event) {
18631859 keyEventHandled = true ;
18641860 return KeyEventResult .handled;
1865- };
1866- // ignore: prefer_function_declarations_over_variables
1867- final FocusOnKeyEventCallback handleEventCallback = (FocusNode node, KeyEvent event) {
1861+ }
1862+ KeyEventResult handleEventCallback (FocusNode node, KeyEvent event) {
18681863 keyEventHandled = true ;
18691864 return KeyEventResult .handled;
1870- };
1871- // ignore: prefer_function_declarations_over_variables
1872- final FocusOnKeyCallback ignoreCallback = (FocusNode node, RawKeyEvent event) => KeyEventResult .ignored;
1873- // ignore: prefer_function_declarations_over_variables
1874- final FocusOnKeyEventCallback ignoreEventCallback = (FocusNode node, KeyEvent event) => KeyEventResult .ignored;
1865+ }
1866+ KeyEventResult ignoreCallback (FocusNode node, RawKeyEvent event) => KeyEventResult .ignored;
1867+ KeyEventResult ignoreEventCallback (FocusNode node, KeyEvent event) => KeyEventResult .ignored;
18751868 focusNode.onKey = ignoreCallback;
18761869 focusNode.onKeyEvent = ignoreEventCallback;
18771870 focusNode.descendantsAreFocusable = false ;
@@ -1974,6 +1967,7 @@ void main() {
19741967 expect (containerNode.hasFocus, isFalse);
19751968 expect (unfocusableNode.hasFocus, isFalse);
19761969 });
1970+
19771971 // Regression test for https://github.com/flutter/flutter/issues/61700
19781972 testWidgets ("ExcludeFocus doesn't transfer focus to another descendant." , (WidgetTester tester) async {
19791973 final FocusNode parentFocusNode = FocusNode (debugLabel: 'group' );
0 commit comments