@@ -532,6 +532,72 @@ void main() {
532532 expect (insertedNode.hasFocus, isFalse);
533533 });
534534
535+ testWidgets ('Setting parentNode determines focus scope tree hierarchy.' , (WidgetTester tester) async {
536+ final FocusScopeNode topNode = FocusScopeNode (debugLabel: 'Top' );
537+ final FocusScopeNode parentNode = FocusScopeNode (debugLabel: 'Parent' );
538+ final FocusScopeNode childNode = FocusScopeNode (debugLabel: 'Child' );
539+ final FocusScopeNode insertedNode = FocusScopeNode (debugLabel: 'Inserted' );
540+
541+ await tester.pumpWidget (
542+ FocusScope .withExternalFocusNode (
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 (),
556+ ),
557+ )
558+ ],
559+ ),
560+ ),
561+ );
562+ await tester.pump ();
563+
564+ expect (childNode.hasFocus, isTrue);
565+ expect (parentNode.hasFocus, isTrue);
566+ expect (topNode.hasFocus, isTrue);
567+
568+ // Check that inserting a Focus in between doesn't reparent the child.
569+ await tester.pumpWidget (
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 (
584+ autofocus: true ,
585+ child: SizedBox (),
586+ ),
587+ ),
588+ )
589+ ],
590+ ),
591+ ),
592+ );
593+ await tester.pump ();
594+
595+ expect (childNode.hasFocus, isTrue);
596+ expect (parentNode.hasFocus, isTrue);
597+ expect (topNode.hasFocus, isTrue);
598+ expect (insertedNode.hasFocus, isFalse);
599+ });
600+
535601 // Arguably, this isn't correct behavior, but it is what happens now.
536602 testWidgets ("Removing focused widget doesn't move focus to next widget within FocusScope" , (WidgetTester tester) async {
537603 final GlobalKey <TestFocusState > keyA = GlobalKey ();
0 commit comments