Skip to content

Commit

Permalink
[reland] Migrate ListTile TextTheme TextStyle references to Materia…
Browse files Browse the repository at this point in the history
…l 3 (#102167)
  • Loading branch information
TahaTesser committed May 25, 2022
1 parent cb9a1d6 commit 78a0d3d
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 13 deletions.
14 changes: 9 additions & 5 deletions packages/flutter/lib/src/material/list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -657,10 +657,10 @@ class ListTile extends StatelessWidget {
final TextStyle textStyle;
switch(style ?? tileTheme.style ?? theme.listTileTheme.style ?? ListTileStyle.list) {
case ListTileStyle.drawer:
textStyle = theme.textTheme.bodyText1!;
textStyle = theme.useMaterial3 ? theme.textTheme.bodyMedium! : theme.textTheme.bodyText1!;
break;
case ListTileStyle.list:
textStyle = theme.textTheme.subtitle1!;
textStyle = theme.useMaterial3 ? theme.textTheme.titleMedium! : theme.textTheme.subtitle1!;
break;
}
final Color? color = _textColor(theme, tileTheme, textStyle.color);
Expand All @@ -670,15 +670,19 @@ class ListTile extends StatelessWidget {
}

TextStyle _subtitleTextStyle(ThemeData theme, ListTileThemeData tileTheme) {
final TextStyle textStyle = theme.textTheme.bodyText2!;
final Color? color = _textColor(theme, tileTheme, theme.textTheme.caption!.color);
final TextStyle textStyle = theme.useMaterial3 ? theme.textTheme.bodyMedium! : theme.textTheme.bodyText2!;
final Color? color = _textColor(
theme,
tileTheme,
theme.useMaterial3 ? theme.textTheme.bodySmall!.color : theme.textTheme.caption!.color,
);
return _isDenseLayout(theme, tileTheme)
? textStyle.copyWith(color: color, fontSize: 12.0)
: textStyle.copyWith(color: color);
}

TextStyle _trailingAndLeadingTextStyle(ThemeData theme, ListTileThemeData tileTheme) {
final TextStyle textStyle = theme.textTheme.bodyText2!;
final TextStyle textStyle = theme.useMaterial3 ? theme.textTheme.bodyMedium! : theme.textTheme.bodyText2!;
final Color? color = _textColor(theme, tileTheme, textStyle.color);
return textStyle.copyWith(color: color);
}
Expand Down
155 changes: 147 additions & 8 deletions packages/flutter/test/material/list_tile_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2104,6 +2104,7 @@ void main() {
ListTileStyle? style,
}) {
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: Material(
child: Center(
child: Builder(
Expand Down Expand Up @@ -2181,6 +2182,7 @@ void main() {
ListTileStyle? style,
}) {
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: Material(
child: Center(
child: Builder(
Expand All @@ -2207,25 +2209,25 @@ void main() {
// ListTile - ListTileStyle.list (default).
await tester.pumpWidget(buildFrame());
RenderParagraph leading = _getTextRenderObject(tester, 'leading');
expect(leading.text.style!.color, theme.textTheme.bodyText2!.color);
expect(leading.text.style!.color, theme.textTheme.bodyMedium!.color);
RenderParagraph title = _getTextRenderObject(tester, 'title');
expect(title.text.style!.color, theme.textTheme.subtitle1!.color);
expect(title.text.style!.color, theme.textTheme.titleMedium!.color);
RenderParagraph subtitle = _getTextRenderObject(tester, 'subtitle');
expect(subtitle.text.style!.color, theme.textTheme.caption!.color);
expect(subtitle.text.style!.color, theme.textTheme.bodySmall!.color);
RenderParagraph trailing = _getTextRenderObject(tester, 'trailing');
expect(trailing.text.style!.color, theme.textTheme.bodyText2!.color);
expect(trailing.text.style!.color, theme.textTheme.bodyMedium!.color);

// ListTile - ListTileStyle.drawer.
await tester.pumpWidget(buildFrame(style: ListTileStyle.drawer));
await tester.pumpAndSettle();
leading = _getTextRenderObject(tester, 'leading');
expect(leading.text.style!.color, theme.textTheme.bodyText2!.color);
expect(leading.text.style!.color, theme.textTheme.bodyMedium!.color);
title = _getTextRenderObject(tester, 'title');
expect(title.text.style!.color, theme.textTheme.bodyText1!.color);
expect(title.text.style!.color, theme.textTheme.bodyLarge!.color);
subtitle = _getTextRenderObject(tester, 'subtitle');
expect(subtitle.text.style!.color, theme.textTheme.caption!.color);
expect(subtitle.text.style!.color, theme.textTheme.bodySmall!.color);
trailing = _getTextRenderObject(tester, 'trailing');
expect(trailing.text.style!.color, theme.textTheme.bodyText2!.color);
expect(trailing.text.style!.color, theme.textTheme.bodyMedium!.color);
});

testWidgets('Default ListTile debugFillProperties', (WidgetTester tester) async {
Expand Down Expand Up @@ -2299,6 +2301,143 @@ void main() {
expect(description[22], 'minVerticalPadding: 2.0');
expect(description[23], 'minLeadingWidth: 6.0');
});

group('Material 2', () {
// Tests that are only relevant for Material 2. Once ThemeData.useMaterial3
// is turned on by default, these tests can be removed.

testWidgets('ListTile font size', (WidgetTester tester) async {
Widget buildFrame({
bool dense = false,
bool enabled = true,
bool selected = false,
ListTileStyle? style,
}) {
return MaterialApp(
home: Material(
child: Center(
child: Builder(
builder: (BuildContext context) {
return ListTile(
dense: dense,
enabled: enabled,
selected: selected,
style: style,
leading: const TestText('leading'),
title: const TestText('title'),
subtitle: const TestText('subtitle') ,
trailing: const TestText('trailing'),
);
},
),
),
),
);
}

// ListTile - ListTileStyle.list (default).
await tester.pumpWidget(buildFrame());
RenderParagraph leading = _getTextRenderObject(tester, 'leading');
expect(leading.text.style!.fontSize, 14.0);
RenderParagraph title = _getTextRenderObject(tester, 'title');
expect(title.text.style!.fontSize, 16.0);
RenderParagraph subtitle = _getTextRenderObject(tester, 'subtitle');
expect(subtitle.text.style!.fontSize, 14.0);
RenderParagraph trailing = _getTextRenderObject(tester, 'trailing');
expect(trailing.text.style!.fontSize, 14.0);

// ListTile - Densed - ListTileStyle.list (default).
await tester.pumpWidget(buildFrame(dense: true));
await tester.pumpAndSettle();
leading = _getTextRenderObject(tester, 'leading');
expect(leading.text.style!.fontSize, 14.0);
title = _getTextRenderObject(tester, 'title');
expect(title.text.style!.fontSize, 13.0);
subtitle = _getTextRenderObject(tester, 'subtitle');
expect(subtitle.text.style!.fontSize, 12.0);
trailing = _getTextRenderObject(tester, 'trailing');
expect(trailing.text.style!.fontSize, 14.0);

// ListTile - ListTileStyle.drawer.
await tester.pumpWidget(buildFrame(style: ListTileStyle.drawer));
await tester.pumpAndSettle();
leading = _getTextRenderObject(tester, 'leading');
expect(leading.text.style!.fontSize, 14.0);
title = _getTextRenderObject(tester, 'title');
expect(title.text.style!.fontSize, 14.0);
subtitle = _getTextRenderObject(tester, 'subtitle');
expect(subtitle.text.style!.fontSize, 14.0);
trailing = _getTextRenderObject(tester, 'trailing');
expect(trailing.text.style!.fontSize, 14.0);

// ListTile - Densed - ListTileStyle.drawer.
await tester.pumpWidget(buildFrame(dense: true, style: ListTileStyle.drawer));
await tester.pumpAndSettle();
leading = _getTextRenderObject(tester, 'leading');
expect(leading.text.style!.fontSize, 14.0);
title = _getTextRenderObject(tester, 'title');
expect(title.text.style!.fontSize, 13.0);
subtitle = _getTextRenderObject(tester, 'subtitle');
expect(subtitle.text.style!.fontSize, 12.0);
trailing = _getTextRenderObject(tester, 'trailing');
expect(trailing.text.style!.fontSize, 14.0);
});

testWidgets('ListTile text color', (WidgetTester tester) async {
Widget buildFrame({
bool dense = false,
bool enabled = true,
bool selected = false,
ListTileStyle? style,
}) {
return MaterialApp(
home: Material(
child: Center(
child: Builder(
builder: (BuildContext context) {
return ListTile(
dense: dense,
enabled: enabled,
selected: selected,
style: style,
leading: const TestText('leading'),
title: const TestText('title'),
subtitle: const TestText('subtitle') ,
trailing: const TestText('trailing'),
);
},
),
),
),
);
}

final ThemeData theme = ThemeData();

// ListTile - ListTileStyle.list (default).
await tester.pumpWidget(buildFrame());
RenderParagraph leading = _getTextRenderObject(tester, 'leading');
expect(leading.text.style!.color, theme.textTheme.bodyText2!.color);
RenderParagraph title = _getTextRenderObject(tester, 'title');
expect(title.text.style!.color, theme.textTheme.subtitle1!.color);
RenderParagraph subtitle = _getTextRenderObject(tester, 'subtitle');
expect(subtitle.text.style!.color, theme.textTheme.caption!.color);
RenderParagraph trailing = _getTextRenderObject(tester, 'trailing');
expect(trailing.text.style!.color, theme.textTheme.bodyText2!.color);

// ListTile - ListTileStyle.drawer.
await tester.pumpWidget(buildFrame(style: ListTileStyle.drawer));
await tester.pumpAndSettle();
leading = _getTextRenderObject(tester, 'leading');
expect(leading.text.style!.color, theme.textTheme.bodyText2!.color);
title = _getTextRenderObject(tester, 'title');
expect(title.text.style!.color, theme.textTheme.subtitle1!.color);
subtitle = _getTextRenderObject(tester, 'subtitle');
expect(subtitle.text.style!.color, theme.textTheme.caption!.color);
trailing = _getTextRenderObject(tester, 'trailing');
expect(trailing.text.style!.color, theme.textTheme.bodyText2!.color);
});
});
}

RenderParagraph _getTextRenderObject(WidgetTester tester, String text) {
Expand Down

0 comments on commit 78a0d3d

Please sign in to comment.