@@ -178,7 +178,7 @@ void main() {
178
178
expect (box.size.height - oldHeight, greaterThanOrEqualTo (100.0 )); // 100 + some margin
179
179
});
180
180
181
- testWidgets ('ExpansionPanelList does not merge header when canTapOnHeader is false' , (WidgetTester tester) async {
181
+ testWidgets ('Material2 - ExpansionPanelList does not merge header when canTapOnHeader is false' , (WidgetTester tester) async {
182
182
final SemanticsHandle handle = tester.ensureSemantics ();
183
183
final Key headerKey = UniqueKey ();
184
184
await tester.pumpWidget (
@@ -226,6 +226,58 @@ void main() {
226
226
handle.dispose ();
227
227
});
228
228
229
+ testWidgets ('Material3 - ExpansionPanelList does not merge header when canTapOnHeader is false' , (WidgetTester tester) async {
230
+ final SemanticsHandle handle = tester.ensureSemantics ();
231
+ final Key headerKey = UniqueKey ();
232
+ await tester.pumpWidget (
233
+ MaterialApp (
234
+ home: ExpansionPanelListSemanticsTest (headerKey: headerKey),
235
+ ),
236
+ );
237
+
238
+ // Make sure custom gesture detector widget is clickable.
239
+ await tester.tap (find.text ('head1' ));
240
+ await tester.pump ();
241
+
242
+ final ExpansionPanelListSemanticsTestState state =
243
+ tester.state (find.byType (ExpansionPanelListSemanticsTest ));
244
+ expect (state.headerTapped, true );
245
+
246
+ // Check the expansion icon semantics does not merged with header widget.
247
+ final Finder expansionIcon = find.descendant (
248
+ of: find.ancestor (
249
+ of: find.byKey (headerKey),
250
+ matching: find.byType (Row ),
251
+ ),
252
+ matching: find.byType (ExpandIcon ),
253
+ );
254
+
255
+ expect (tester.getSemantics (expansionIcon), matchesSemantics (
256
+ label: 'Expand' ,
257
+ children: < Matcher > [
258
+ matchesSemantics (
259
+ isButton: true ,
260
+ hasEnabledState: true ,
261
+ isEnabled: true ,
262
+ isFocusable: true ,
263
+ hasTapAction: true ,
264
+ ),
265
+ ],
266
+ ));
267
+
268
+ // Check custom header widget semantics is preserved.
269
+ final Finder headerWidget = find.descendant (
270
+ of: find.byKey (headerKey),
271
+ matching: find.byType (RichText ),
272
+ );
273
+ expect (tester.getSemantics (headerWidget), matchesSemantics (
274
+ label: 'head1' ,
275
+ hasTapAction: true ,
276
+ ));
277
+
278
+ handle.dispose ();
279
+ });
280
+
229
281
testWidgets ('Multiple Panel List test' , (WidgetTester tester) async {
230
282
await tester.pumpWidget (
231
283
MaterialApp (
@@ -998,7 +1050,7 @@ void main() {
998
1050
await tester.pumpAndSettle ();
999
1051
});
1000
1052
1001
- testWidgets ('Panel header has semantics, canTapOnHeader = false ' , (WidgetTester tester) async {
1053
+ testWidgets ('Material2 - Panel header has semantics, canTapOnHeader = false' , (WidgetTester tester) async {
1002
1054
const Key expandedKey = Key ('expanded' );
1003
1055
const Key collapsedKey = Key ('collapsed' );
1004
1056
const DefaultMaterialLocalizations localizations = DefaultMaterialLocalizations ();
@@ -1083,6 +1135,99 @@ void main() {
1083
1135
handle.dispose ();
1084
1136
});
1085
1137
1138
+ testWidgets ('Material3 - Panel header has semantics, canTapOnHeader = false' , (WidgetTester tester) async {
1139
+ const Key expandedKey = Key ('expanded' );
1140
+ const Key collapsedKey = Key ('collapsed' );
1141
+ const DefaultMaterialLocalizations localizations = DefaultMaterialLocalizations ();
1142
+ final SemanticsHandle handle = tester.ensureSemantics ();
1143
+ final List <ExpansionPanel > demoItems = < ExpansionPanel > [
1144
+ ExpansionPanel (
1145
+ headerBuilder: (BuildContext context, bool isExpanded) {
1146
+ return const Text ('Expanded' , key: expandedKey);
1147
+ },
1148
+ body: const SizedBox (height: 100.0 ),
1149
+ isExpanded: true ,
1150
+ ),
1151
+ ExpansionPanel (
1152
+ headerBuilder: (BuildContext context, bool isExpanded) {
1153
+ return const Text ('Collapsed' , key: collapsedKey);
1154
+ },
1155
+ body: const SizedBox (height: 100.0 ),
1156
+ ),
1157
+ ];
1158
+
1159
+ final ExpansionPanelList expansionList = ExpansionPanelList (
1160
+ children: demoItems,
1161
+ );
1162
+
1163
+ await tester.pumpWidget (
1164
+ MaterialApp (
1165
+ home: SingleChildScrollView (
1166
+ child: expansionList,
1167
+ ),
1168
+ ),
1169
+ );
1170
+
1171
+ // Check the semantics of [ExpandIcon] for expanded panel.
1172
+ final Finder expandedIcon = find.descendant (
1173
+ of: find.ancestor (
1174
+ of: find.byKey (expandedKey),
1175
+ matching: find.byType (Row ),
1176
+ ),
1177
+ matching: find.byType (ExpandIcon ),
1178
+ );
1179
+
1180
+ expect (tester.getSemantics (expandedIcon), matchesSemantics (
1181
+ label: 'Collapse' ,
1182
+ onTapHint: localizations.expandedIconTapHint,
1183
+ children: < Matcher > [
1184
+ matchesSemantics (
1185
+ isButton: true ,
1186
+ hasEnabledState: true ,
1187
+ isEnabled: true ,
1188
+ isFocusable: true ,
1189
+ hasTapAction: true ,
1190
+ ),
1191
+ ],
1192
+ ));
1193
+
1194
+ // Check the semantics of the header widget for expanded panel.
1195
+ final Finder expandedHeader = find.byKey (expandedKey);
1196
+ expect (tester.getSemantics (expandedHeader), matchesSemantics (
1197
+ label: 'Expanded' ,
1198
+ ));
1199
+
1200
+ // Check the semantics of [ExpandIcon] for collapsed panel.
1201
+ final Finder collapsedIcon = find.descendant (
1202
+ of: find.ancestor (
1203
+ of: find.byKey (collapsedKey),
1204
+ matching: find.byType (Row ),
1205
+ ),
1206
+ matching: find.byType (ExpandIcon ),
1207
+ );
1208
+ expect (tester.getSemantics (collapsedIcon), matchesSemantics (
1209
+ label: 'Expand' ,
1210
+ onTapHint: localizations.collapsedIconTapHint,
1211
+ children: < Matcher > [
1212
+ matchesSemantics (
1213
+ isButton: true ,
1214
+ hasEnabledState: true ,
1215
+ isEnabled: true ,
1216
+ isFocusable: true ,
1217
+ hasTapAction: true ,
1218
+ ),
1219
+ ],
1220
+ ));
1221
+
1222
+ // Check the semantics of the header widget for expanded panel.
1223
+ final Finder collapsedHeader = find.byKey (collapsedKey);
1224
+ expect (tester.getSemantics (collapsedHeader), matchesSemantics (
1225
+ label: 'Collapsed' ,
1226
+ ));
1227
+
1228
+ handle.dispose ();
1229
+ });
1230
+
1086
1231
testWidgets ('Panel header has semantics, canTapOnHeader = true' , (WidgetTester tester) async {
1087
1232
const Key expandedKey = Key ('expanded' );
1088
1233
const Key collapsedKey = Key ('collapsed' );
0 commit comments