@@ -420,7 +420,7 @@ void main() {
420
420
expect (find.text ('b' ), findsOneWidget);
421
421
});
422
422
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 {
424
424
final GlobalKey <TestFocusState > keyA = GlobalKey ();
425
425
final FocusScopeNode parentFocusScope = FocusScopeNode (debugLabel: 'Parent Scope Node' );
426
426
final FocusScopeNode childFocusScope = FocusScopeNode (debugLabel: 'Child Scope Node' );
@@ -540,24 +540,24 @@ void main() {
540
540
541
541
await tester.pumpWidget (
542
542
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 (),
549
556
),
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
+ ],
560
559
),
560
+ ),
561
561
);
562
562
await tester.pump ();
563
563
@@ -568,27 +568,27 @@ void main() {
568
568
// Check that inserting a Focus in between doesn't reparent the child.
569
569
await tester.pumpWidget (
570
570
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 (
584
584
autofocus: true ,
585
585
child: SizedBox (),
586
586
),
587
- ),
588
- )
589
- ],
590
- ),
587
+ ),
588
+ )
589
+ ],
591
590
),
591
+ ),
592
592
);
593
593
await tester.pump ();
594
594
@@ -1673,6 +1673,7 @@ void main() {
1673
1673
await pumpTest (traverseScope1: true );
1674
1674
expect (scope1.traversalDescendants, equals (< FocusNode > [focus2, focus1, scope2]));
1675
1675
});
1676
+
1676
1677
testWidgets ('descendantsAreFocusable works as expected.' , (WidgetTester tester) async {
1677
1678
final GlobalKey key1 = GlobalKey (debugLabel: '1' );
1678
1679
final GlobalKey key2 = GlobalKey (debugLabel: '2' );
@@ -1756,13 +1757,11 @@ void main() {
1756
1757
final GlobalKey key1 = GlobalKey (debugLabel: '1' );
1757
1758
final FocusNode focusNode = FocusNode ();
1758
1759
bool ? keyEventHandled;
1759
- // ignore: prefer_function_declarations_over_variables
1760
- final FocusOnKeyCallback handleCallback = (FocusNode node, RawKeyEvent event) {
1760
+ KeyEventResult handleCallback (FocusNode node, RawKeyEvent event) {
1761
1761
keyEventHandled = true ;
1762
1762
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;
1766
1765
Focus focusWidget = Focus (
1767
1766
onKey: ignoreCallback, // This one does nothing.
1768
1767
focusNode: focusNode,
@@ -1807,13 +1806,11 @@ void main() {
1807
1806
final GlobalKey key1 = GlobalKey (debugLabel: '1' );
1808
1807
final FocusNode focusNode = FocusNode ();
1809
1808
bool ? keyEventHandled;
1810
- // ignore: prefer_function_declarations_over_variables
1811
- final FocusOnKeyEventCallback handleEventCallback = (FocusNode node, KeyEvent event) {
1809
+ KeyEventResult handleEventCallback (FocusNode node, KeyEvent event) {
1812
1810
keyEventHandled = true ;
1813
1811
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;
1817
1814
Focus focusWidget = Focus (
1818
1815
onKeyEvent: ignoreEventCallback, // This one does nothing.
1819
1816
focusNode: focusNode,
@@ -1858,20 +1855,16 @@ void main() {
1858
1855
final GlobalKey key1 = GlobalKey (debugLabel: '1' );
1859
1856
final FocusNode focusNode = FocusNode ();
1860
1857
bool ? keyEventHandled;
1861
- // ignore: prefer_function_declarations_over_variables
1862
- final FocusOnKeyCallback handleCallback = (FocusNode node, RawKeyEvent event) {
1858
+ KeyEventResult handleCallback (FocusNode node, RawKeyEvent event) {
1863
1859
keyEventHandled = true ;
1864
1860
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) {
1868
1863
keyEventHandled = true ;
1869
1864
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;
1875
1868
focusNode.onKey = ignoreCallback;
1876
1869
focusNode.onKeyEvent = ignoreEventCallback;
1877
1870
focusNode.descendantsAreFocusable = false ;
@@ -1974,6 +1967,7 @@ void main() {
1974
1967
expect (containerNode.hasFocus, isFalse);
1975
1968
expect (unfocusableNode.hasFocus, isFalse);
1976
1969
});
1970
+
1977
1971
// Regression test for https://github.com/flutter/flutter/issues/61700
1978
1972
testWidgets ("ExcludeFocus doesn't transfer focus to another descendant." , (WidgetTester tester) async {
1979
1973
final FocusNode parentFocusNode = FocusNode (debugLabel: 'group' );
0 commit comments