Skip to content

Commit 78a0d3d

Browse files
authored
[reland] Migrate ListTile TextTheme TextStyle references to Material 3 (#102167)
1 parent cb9a1d6 commit 78a0d3d

File tree

2 files changed

+156
-13
lines changed

2 files changed

+156
-13
lines changed

packages/flutter/lib/src/material/list_tile.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -657,10 +657,10 @@ class ListTile extends StatelessWidget {
657657
final TextStyle textStyle;
658658
switch(style ?? tileTheme.style ?? theme.listTileTheme.style ?? ListTileStyle.list) {
659659
case ListTileStyle.drawer:
660-
textStyle = theme.textTheme.bodyText1!;
660+
textStyle = theme.useMaterial3 ? theme.textTheme.bodyMedium! : theme.textTheme.bodyText1!;
661661
break;
662662
case ListTileStyle.list:
663-
textStyle = theme.textTheme.subtitle1!;
663+
textStyle = theme.useMaterial3 ? theme.textTheme.titleMedium! : theme.textTheme.subtitle1!;
664664
break;
665665
}
666666
final Color? color = _textColor(theme, tileTheme, textStyle.color);
@@ -670,15 +670,19 @@ class ListTile extends StatelessWidget {
670670
}
671671

672672
TextStyle _subtitleTextStyle(ThemeData theme, ListTileThemeData tileTheme) {
673-
final TextStyle textStyle = theme.textTheme.bodyText2!;
674-
final Color? color = _textColor(theme, tileTheme, theme.textTheme.caption!.color);
673+
final TextStyle textStyle = theme.useMaterial3 ? theme.textTheme.bodyMedium! : theme.textTheme.bodyText2!;
674+
final Color? color = _textColor(
675+
theme,
676+
tileTheme,
677+
theme.useMaterial3 ? theme.textTheme.bodySmall!.color : theme.textTheme.caption!.color,
678+
);
675679
return _isDenseLayout(theme, tileTheme)
676680
? textStyle.copyWith(color: color, fontSize: 12.0)
677681
: textStyle.copyWith(color: color);
678682
}
679683

680684
TextStyle _trailingAndLeadingTextStyle(ThemeData theme, ListTileThemeData tileTheme) {
681-
final TextStyle textStyle = theme.textTheme.bodyText2!;
685+
final TextStyle textStyle = theme.useMaterial3 ? theme.textTheme.bodyMedium! : theme.textTheme.bodyText2!;
682686
final Color? color = _textColor(theme, tileTheme, textStyle.color);
683687
return textStyle.copyWith(color: color);
684688
}

packages/flutter/test/material/list_tile_test.dart

Lines changed: 147 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,6 +2104,7 @@ void main() {
21042104
ListTileStyle? style,
21052105
}) {
21062106
return MaterialApp(
2107+
theme: ThemeData(useMaterial3: true),
21072108
home: Material(
21082109
child: Center(
21092110
child: Builder(
@@ -2181,6 +2182,7 @@ void main() {
21812182
ListTileStyle? style,
21822183
}) {
21832184
return MaterialApp(
2185+
theme: ThemeData(useMaterial3: true),
21842186
home: Material(
21852187
child: Center(
21862188
child: Builder(
@@ -2207,25 +2209,25 @@ void main() {
22072209
// ListTile - ListTileStyle.list (default).
22082210
await tester.pumpWidget(buildFrame());
22092211
RenderParagraph leading = _getTextRenderObject(tester, 'leading');
2210-
expect(leading.text.style!.color, theme.textTheme.bodyText2!.color);
2212+
expect(leading.text.style!.color, theme.textTheme.bodyMedium!.color);
22112213
RenderParagraph title = _getTextRenderObject(tester, 'title');
2212-
expect(title.text.style!.color, theme.textTheme.subtitle1!.color);
2214+
expect(title.text.style!.color, theme.textTheme.titleMedium!.color);
22132215
RenderParagraph subtitle = _getTextRenderObject(tester, 'subtitle');
2214-
expect(subtitle.text.style!.color, theme.textTheme.caption!.color);
2216+
expect(subtitle.text.style!.color, theme.textTheme.bodySmall!.color);
22152217
RenderParagraph trailing = _getTextRenderObject(tester, 'trailing');
2216-
expect(trailing.text.style!.color, theme.textTheme.bodyText2!.color);
2218+
expect(trailing.text.style!.color, theme.textTheme.bodyMedium!.color);
22172219

22182220
// ListTile - ListTileStyle.drawer.
22192221
await tester.pumpWidget(buildFrame(style: ListTileStyle.drawer));
22202222
await tester.pumpAndSettle();
22212223
leading = _getTextRenderObject(tester, 'leading');
2222-
expect(leading.text.style!.color, theme.textTheme.bodyText2!.color);
2224+
expect(leading.text.style!.color, theme.textTheme.bodyMedium!.color);
22232225
title = _getTextRenderObject(tester, 'title');
2224-
expect(title.text.style!.color, theme.textTheme.bodyText1!.color);
2226+
expect(title.text.style!.color, theme.textTheme.bodyLarge!.color);
22252227
subtitle = _getTextRenderObject(tester, 'subtitle');
2226-
expect(subtitle.text.style!.color, theme.textTheme.caption!.color);
2228+
expect(subtitle.text.style!.color, theme.textTheme.bodySmall!.color);
22272229
trailing = _getTextRenderObject(tester, 'trailing');
2228-
expect(trailing.text.style!.color, theme.textTheme.bodyText2!.color);
2230+
expect(trailing.text.style!.color, theme.textTheme.bodyMedium!.color);
22292231
});
22302232

22312233
testWidgets('Default ListTile debugFillProperties', (WidgetTester tester) async {
@@ -2299,6 +2301,143 @@ void main() {
22992301
expect(description[22], 'minVerticalPadding: 2.0');
23002302
expect(description[23], 'minLeadingWidth: 6.0');
23012303
});
2304+
2305+
group('Material 2', () {
2306+
// Tests that are only relevant for Material 2. Once ThemeData.useMaterial3
2307+
// is turned on by default, these tests can be removed.
2308+
2309+
testWidgets('ListTile font size', (WidgetTester tester) async {
2310+
Widget buildFrame({
2311+
bool dense = false,
2312+
bool enabled = true,
2313+
bool selected = false,
2314+
ListTileStyle? style,
2315+
}) {
2316+
return MaterialApp(
2317+
home: Material(
2318+
child: Center(
2319+
child: Builder(
2320+
builder: (BuildContext context) {
2321+
return ListTile(
2322+
dense: dense,
2323+
enabled: enabled,
2324+
selected: selected,
2325+
style: style,
2326+
leading: const TestText('leading'),
2327+
title: const TestText('title'),
2328+
subtitle: const TestText('subtitle') ,
2329+
trailing: const TestText('trailing'),
2330+
);
2331+
},
2332+
),
2333+
),
2334+
),
2335+
);
2336+
}
2337+
2338+
// ListTile - ListTileStyle.list (default).
2339+
await tester.pumpWidget(buildFrame());
2340+
RenderParagraph leading = _getTextRenderObject(tester, 'leading');
2341+
expect(leading.text.style!.fontSize, 14.0);
2342+
RenderParagraph title = _getTextRenderObject(tester, 'title');
2343+
expect(title.text.style!.fontSize, 16.0);
2344+
RenderParagraph subtitle = _getTextRenderObject(tester, 'subtitle');
2345+
expect(subtitle.text.style!.fontSize, 14.0);
2346+
RenderParagraph trailing = _getTextRenderObject(tester, 'trailing');
2347+
expect(trailing.text.style!.fontSize, 14.0);
2348+
2349+
// ListTile - Densed - ListTileStyle.list (default).
2350+
await tester.pumpWidget(buildFrame(dense: true));
2351+
await tester.pumpAndSettle();
2352+
leading = _getTextRenderObject(tester, 'leading');
2353+
expect(leading.text.style!.fontSize, 14.0);
2354+
title = _getTextRenderObject(tester, 'title');
2355+
expect(title.text.style!.fontSize, 13.0);
2356+
subtitle = _getTextRenderObject(tester, 'subtitle');
2357+
expect(subtitle.text.style!.fontSize, 12.0);
2358+
trailing = _getTextRenderObject(tester, 'trailing');
2359+
expect(trailing.text.style!.fontSize, 14.0);
2360+
2361+
// ListTile - ListTileStyle.drawer.
2362+
await tester.pumpWidget(buildFrame(style: ListTileStyle.drawer));
2363+
await tester.pumpAndSettle();
2364+
leading = _getTextRenderObject(tester, 'leading');
2365+
expect(leading.text.style!.fontSize, 14.0);
2366+
title = _getTextRenderObject(tester, 'title');
2367+
expect(title.text.style!.fontSize, 14.0);
2368+
subtitle = _getTextRenderObject(tester, 'subtitle');
2369+
expect(subtitle.text.style!.fontSize, 14.0);
2370+
trailing = _getTextRenderObject(tester, 'trailing');
2371+
expect(trailing.text.style!.fontSize, 14.0);
2372+
2373+
// ListTile - Densed - ListTileStyle.drawer.
2374+
await tester.pumpWidget(buildFrame(dense: true, style: ListTileStyle.drawer));
2375+
await tester.pumpAndSettle();
2376+
leading = _getTextRenderObject(tester, 'leading');
2377+
expect(leading.text.style!.fontSize, 14.0);
2378+
title = _getTextRenderObject(tester, 'title');
2379+
expect(title.text.style!.fontSize, 13.0);
2380+
subtitle = _getTextRenderObject(tester, 'subtitle');
2381+
expect(subtitle.text.style!.fontSize, 12.0);
2382+
trailing = _getTextRenderObject(tester, 'trailing');
2383+
expect(trailing.text.style!.fontSize, 14.0);
2384+
});
2385+
2386+
testWidgets('ListTile text color', (WidgetTester tester) async {
2387+
Widget buildFrame({
2388+
bool dense = false,
2389+
bool enabled = true,
2390+
bool selected = false,
2391+
ListTileStyle? style,
2392+
}) {
2393+
return MaterialApp(
2394+
home: Material(
2395+
child: Center(
2396+
child: Builder(
2397+
builder: (BuildContext context) {
2398+
return ListTile(
2399+
dense: dense,
2400+
enabled: enabled,
2401+
selected: selected,
2402+
style: style,
2403+
leading: const TestText('leading'),
2404+
title: const TestText('title'),
2405+
subtitle: const TestText('subtitle') ,
2406+
trailing: const TestText('trailing'),
2407+
);
2408+
},
2409+
),
2410+
),
2411+
),
2412+
);
2413+
}
2414+
2415+
final ThemeData theme = ThemeData();
2416+
2417+
// ListTile - ListTileStyle.list (default).
2418+
await tester.pumpWidget(buildFrame());
2419+
RenderParagraph leading = _getTextRenderObject(tester, 'leading');
2420+
expect(leading.text.style!.color, theme.textTheme.bodyText2!.color);
2421+
RenderParagraph title = _getTextRenderObject(tester, 'title');
2422+
expect(title.text.style!.color, theme.textTheme.subtitle1!.color);
2423+
RenderParagraph subtitle = _getTextRenderObject(tester, 'subtitle');
2424+
expect(subtitle.text.style!.color, theme.textTheme.caption!.color);
2425+
RenderParagraph trailing = _getTextRenderObject(tester, 'trailing');
2426+
expect(trailing.text.style!.color, theme.textTheme.bodyText2!.color);
2427+
2428+
// ListTile - ListTileStyle.drawer.
2429+
await tester.pumpWidget(buildFrame(style: ListTileStyle.drawer));
2430+
await tester.pumpAndSettle();
2431+
leading = _getTextRenderObject(tester, 'leading');
2432+
expect(leading.text.style!.color, theme.textTheme.bodyText2!.color);
2433+
title = _getTextRenderObject(tester, 'title');
2434+
expect(title.text.style!.color, theme.textTheme.subtitle1!.color);
2435+
subtitle = _getTextRenderObject(tester, 'subtitle');
2436+
expect(subtitle.text.style!.color, theme.textTheme.caption!.color);
2437+
trailing = _getTextRenderObject(tester, 'trailing');
2438+
expect(trailing.text.style!.color, theme.textTheme.bodyText2!.color);
2439+
});
2440+
});
23022441
}
23032442

23042443
RenderParagraph _getTextRenderObject(WidgetTester tester, String text) {

0 commit comments

Comments
 (0)