@@ -26,11 +26,26 @@ void main() {
26
26
await tester.pump ();
27
27
}
28
28
29
- group ('ThemeSetting' , () {
30
- Finder findRadioListTileWithTitle (String title) => find.ancestor (
31
- of: find.text (title),
32
- matching: find.byType (RadioListTile <ThemeSetting ?>));
29
+ Finder findRadioListTileWithTitle <T >(String title) => find.ancestor (
30
+ of: find.text (title),
31
+ matching: find.byType (RadioListTile <T >));
32
+
33
+ void checkRadioButtonAppearsChecked <T >(WidgetTester tester, String title, bool expectedIsChecked) {
34
+ check (tester.semantics.find (findRadioListTileWithTitle <T >(title)))
35
+ // `.legacyMatcher()` wrapper just because flutter_checks's
36
+ // `matchesSemantics` doesn't yet have a `hasSelectedState` param
37
+ .legacyMatcher (matchesSemantics (
38
+ label: title,
39
+ isFocusable: true ,
40
+ hasEnabledState: true , isEnabled: true ,
41
+ isInMutuallyExclusiveGroup: true ,
42
+ hasCheckedState: true , isChecked: expectedIsChecked,
43
+ hasSelectedState: true ,
44
+ hasTapAction: true ,
45
+ hasFocusAction: true ));
46
+ }
33
47
48
+ group ('ThemeSetting' , () {
34
49
void checkThemeSetting (WidgetTester tester, {
35
50
required ThemeSetting ? expectedThemeSetting,
36
51
}) {
@@ -40,19 +55,7 @@ void main() {
40
55
ThemeSetting .dark => 'Dark' ,
41
56
};
42
57
for (final title in ['System' , 'Light' , 'Dark' ]) {
43
- final expectedIsChecked = title == expectedCheckedTitle;
44
- check (tester.semantics.find (findRadioListTileWithTitle (title)))
45
- // `.legacyMatcher()` wrapper just because flutter_checks's
46
- // `matchesSemantics` doesn't yet have a `hasSelectedState` param
47
- .legacyMatcher (matchesSemantics (
48
- label: title,
49
- isFocusable: true ,
50
- hasEnabledState: true , isEnabled: true ,
51
- isInMutuallyExclusiveGroup: true ,
52
- hasCheckedState: true , isChecked: expectedIsChecked,
53
- hasSelectedState: true ,
54
- hasTapAction: true ,
55
- hasFocusAction: true ));
58
+ checkRadioButtonAppearsChecked <ThemeSetting ?>(tester, title, title == expectedCheckedTitle);
56
59
}
57
60
check (testBinding.globalStore)
58
61
.settings.themeSetting.equals (expectedThemeSetting);
@@ -67,13 +70,13 @@ void main() {
67
70
check (Theme .of (element)).brightness.equals (Brightness .light);
68
71
checkThemeSetting (tester, expectedThemeSetting: ThemeSetting .light);
69
72
70
- await tester.tap (findRadioListTileWithTitle ('Dark' ));
73
+ await tester.tap (findRadioListTileWithTitle < ThemeSetting ?> ('Dark' ));
71
74
await tester.pump ();
72
75
await tester.pump (Duration (milliseconds: 250 )); // wait for transition
73
76
check (Theme .of (element)).brightness.equals (Brightness .dark);
74
77
checkThemeSetting (tester, expectedThemeSetting: ThemeSetting .dark);
75
78
76
- await tester.tap (findRadioListTileWithTitle ('System' ));
79
+ await tester.tap (findRadioListTileWithTitle < ThemeSetting ?> ('System' ));
77
80
await tester.pump ();
78
81
await tester.pump (Duration (milliseconds: 250 )); // wait for transition
79
82
check (Theme .of (element)).brightness.equals (Brightness .light);
0 commit comments