File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -433,7 +433,9 @@ abstract class FocusTraversalPolicy with Diagnosticable {
433
433
// finds.
434
434
assert ((){
435
435
final Set <FocusNode > difference = sortedDescendants.toSet ().difference (scope.traversalDescendants.toSet ());
436
- if (currentNode.skipTraversal) {
436
+ if (currentNode.skipTraversal || ! currentNode.canRequestFocus) {
437
+ // The scope.traversalDescendants will not contain currentNode if it
438
+ // skips traversal or not focusable.
437
439
assert (
438
440
difference.length == 1 && difference.contains (currentNode),
439
441
'Sorted descendants contains different nodes than FocusScopeNode.traversalDescendants would. '
Original file line number Diff line number Diff line change @@ -596,6 +596,41 @@ void main() {
596
596
expect (scope.hasFocus, isTrue);
597
597
});
598
598
599
+ testWidgetsWithLeakTracking ('Requesting nextFocus on node focuses its descendant' , (WidgetTester tester) async {
600
+ for (final bool canRequestFocus in < bool > {true , false }) {
601
+ final FocusNode node1 = FocusNode ();
602
+ final FocusNode node2 = FocusNode ();
603
+ addTearDown (() {
604
+ node1.dispose ();
605
+ node2.dispose ();
606
+ });
607
+ await tester.pumpWidget (
608
+ Directionality (
609
+ textDirection: TextDirection .ltr,
610
+ child: FocusTraversalGroup (
611
+ policy: ReadingOrderTraversalPolicy (),
612
+ child: FocusScope (
613
+ child: Focus (
614
+ focusNode: node1,
615
+ canRequestFocus: canRequestFocus,
616
+ child: Focus (
617
+ focusNode: node2,
618
+ child: Container (),
619
+ ),
620
+ ),
621
+ ),
622
+ ),
623
+ ),
624
+ );
625
+
626
+ final bool didFindNode = node1.nextFocus ();
627
+ await tester.pump ();
628
+ expect (didFindNode, isTrue);
629
+ expect (node1.hasPrimaryFocus, isFalse);
630
+ expect (node2.hasPrimaryFocus, isTrue);
631
+ }
632
+ });
633
+
599
634
testWidgetsWithLeakTracking ('Move reading focus to previous node.' , (WidgetTester tester) async {
600
635
final GlobalKey key1 = GlobalKey (debugLabel: '1' );
601
636
final GlobalKey key2 = GlobalKey (debugLabel: '2' );
You can’t perform that action at this time.
0 commit comments