@@ -8,17 +8,20 @@ void main() {
88 () {
99 final List <int > menuItems = List <int >.generate (10 , (int index) => index);
1010 final valueListenable = ValueNotifier (menuItems.first);
11- final value = valueListenable.value;
1211
1312 final findDropdownButton = find.byType (DropdownButton2 <int >);
1413 final findDropdownButtonFormField = find.byType (DropdownButtonFormField2 <int >);
15- final findDropdownButtonText =
16- find.descendant (of: findDropdownButton, matching: find.text ('$value ' ));
1714 final findDropdownMenu = find.byType (ListView );
18- final findDropdownMenuText =
19- find.descendant (of: findDropdownMenu, matching: find.text ('$value ' ));
2015
21- testWidgets ('onTap should request focus for both button and menu' ,
16+ final findDropdownButtonFocus = find
17+ .descendant (of: find.byType (DropdownButton2 <int >), matching: find.byType (Focus ))
18+ .first;
19+ final findDropdownButtonText =
20+ find.descendant (of: findDropdownButton, matching: find.text ('${valueListenable .value }' ));
21+ final findSelectedMenuItemText =
22+ find.descendant (of: findDropdownMenu, matching: find.text ('${valueListenable .value }' ));
23+
24+ testWidgets ('onTap should request focus for both button and selected menu item' ,
2225 (WidgetTester tester) async {
2326 await tester.pumpWidget (
2427 MaterialApp (
@@ -39,7 +42,7 @@ void main() {
3942 ),
4043 );
4144
42- final buttonFocusNode = Focus . of ( tester.element (findDropdownButtonText)) ;
45+ final buttonFocusNode = tester.widget < Focus >(findDropdownButtonFocus).focusNode ! ;
4346
4447 expect (findDropdownMenu, findsNothing);
4548 expect (buttonFocusNode.hasFocus, isFalse);
@@ -48,9 +51,9 @@ void main() {
4851 await tester.pumpAndSettle ();
4952
5053 expect (findDropdownMenu, findsOneWidget);
51- final menuFocusNode = Focus .of (tester.element (findDropdownMenuText ));
54+ final selectedMenuItemFocusNode = Focus .of (tester.element (findSelectedMenuItemText ));
5255
53- expect (menuFocusNode .hasPrimaryFocus, isTrue);
56+ expect (selectedMenuItemFocusNode .hasPrimaryFocus, isTrue);
5457 expect (buttonFocusNode.hasFocus, isTrue);
5558 });
5659
@@ -74,7 +77,7 @@ void main() {
7477 ),
7578 );
7679
77- final buttonFocusNode = Focus . of ( tester.element (findDropdownButtonText)) ;
80+ final buttonFocusNode = tester.widget < Focus >(findDropdownButtonFocus).focusNode ! ;
7881
7982 expect (buttonFocusNode.hasFocus, isFalse);
8083
@@ -83,7 +86,7 @@ void main() {
8386
8487 expect (buttonFocusNode.hasFocus, isTrue);
8588
86- await tester.tap (findDropdownMenuText );
89+ await tester.tap (findSelectedMenuItemText );
8790 await tester.pumpAndSettle ();
8891
8992 expect (buttonFocusNode.hasPrimaryFocus, isTrue);
0 commit comments