Skip to content

Commit ce248e8

Browse files
authored
Update misc tests for Material3 (#128712)
1 parent 09b7e56 commit ce248e8

File tree

2 files changed

+65
-27
lines changed

2 files changed

+65
-27
lines changed

examples/api/lib/widgets/app_lifecycle_listener/app_lifecycle_listener.1.dart

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -78,30 +78,29 @@ class _ApplicationExitControlState extends State<ApplicationExitControl> {
7878
return Center(
7979
child: SizedBox(
8080
width: 300,
81-
child: IntrinsicHeight(
82-
child: Column(
83-
children: <Widget>[
84-
RadioListTile<bool>(
85-
title: const Text('Do Not Allow Exit'),
86-
groupValue: _shouldExit,
87-
value: false,
88-
onChanged: _radioChanged,
89-
),
90-
RadioListTile<bool>(
91-
title: const Text('Allow Exit'),
92-
groupValue: _shouldExit,
93-
value: true,
94-
onChanged: _radioChanged,
95-
),
96-
const SizedBox(height: 30),
97-
ElevatedButton(
98-
onPressed: _quit,
99-
child: const Text('Quit'),
100-
),
101-
const SizedBox(height: 30),
102-
Text('Exit Request: $_lastExitResponse'),
103-
],
104-
),
81+
child: Column(
82+
mainAxisSize: MainAxisSize.min,
83+
children: <Widget>[
84+
RadioListTile<bool>(
85+
title: const Text('Do Not Allow Exit'),
86+
groupValue: _shouldExit,
87+
value: false,
88+
onChanged: _radioChanged,
89+
),
90+
RadioListTile<bool>(
91+
title: const Text('Allow Exit'),
92+
groupValue: _shouldExit,
93+
value: true,
94+
onChanged: _radioChanged,
95+
),
96+
const SizedBox(height: 30),
97+
ElevatedButton(
98+
onPressed: _quit,
99+
child: const Text('Quit'),
100+
),
101+
const SizedBox(height: 30),
102+
Text('Exit Request: $_lastExitResponse'),
103+
],
105104
),
106105
),
107106
);

packages/flutter_test/test/accessibility_test.dart

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,12 @@ void main() {
275275
handle.dispose();
276276
});
277277

278-
testWidgets('yellow text on yellow background fails with correct message',
278+
testWidgets('Material2: yellow text on yellow background fails with correct message',
279279
(WidgetTester tester) async {
280280
final SemanticsHandle handle = tester.ensureSemantics();
281281
await tester.pumpWidget(
282282
_boilerplate(
283+
useMaterial3: false,
283284
Container(
284285
width: 200.0,
285286
height: 200.0,
@@ -306,6 +307,38 @@ void main() {
306307
handle.dispose();
307308
});
308309

310+
testWidgets('Material3: yellow text on yellow background fails with correct message',
311+
(WidgetTester tester) async {
312+
final SemanticsHandle handle = tester.ensureSemantics();
313+
await tester.pumpWidget(
314+
_boilerplate(
315+
useMaterial3: true,
316+
Container(
317+
width: 200.0,
318+
height: 200.0,
319+
color: Colors.yellow,
320+
child: const Text(
321+
'this is a test',
322+
style: TextStyle(fontSize: 14.0, color: Colors.yellowAccent),
323+
),
324+
),
325+
),
326+
);
327+
final Evaluation result = await textContrastGuideline.evaluate(tester);
328+
expect(result.passed, false);
329+
expect(
330+
result.reason,
331+
'SemanticsNode#4(Rect.fromLTRB(300.0, 200.0, 500.0, 400.0), '
332+
'label: "this is a test", textDirection: ltr):\n'
333+
'Expected contrast ratio of at least 4.5 but found 1.19 for a font '
334+
'size of 14.0.\n'
335+
'The computed colors was:\n'
336+
'light - Color(0xfffffbfe), dark - Color(0xffffeb3b)\n'
337+
'See also: https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html',
338+
);
339+
handle.dispose();
340+
});
341+
309342
testWidgets('label without corresponding text is skipped',
310343
(WidgetTester tester) async {
311344
final SemanticsHandle handle = tester.ensureSemantics();
@@ -937,5 +970,11 @@ void main() {
937970
});
938971
}
939972

940-
Widget _boilerplate(Widget child) =>
941-
MaterialApp(home: Scaffold(body: Center(child: child)));
973+
Widget _boilerplate(Widget child, { bool? useMaterial3 }) {
974+
return MaterialApp(
975+
theme: ThemeData(useMaterial3: useMaterial3),
976+
home: Scaffold(
977+
body: Center(child: child),
978+
),
979+
);
980+
}

0 commit comments

Comments
 (0)