Update ListTile text defaults to use ColorScheme (#128581)
fixes https://github.com/flutter/flutter/issues/128569 <details> <summary>code sample</summary> ```dart import 'package:flutter/material.dart'; void main() { runApp(const ListTileApp()); } class ListTileApp extends StatelessWidget { const ListTileApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( useMaterial3: true, colorScheme: ColorScheme.fromSeed(seedColor: Colors.red).copyWith( onSurface: Colors.yellow, onSurfaceVariant: Colors.green, ), ), home: const Scaffold( body: Center( child: ListTile( title: Text('title'), subtitle: Text('subtitle'), ), ), ), ); } } ``` </details> # Description M3 ListTile couldn't be customized using `ColorScheme` colors. - This PR updates the list tile text defaults to `ColorScheme` text color tokens. - Improved the `ListTile` template to use the token group. - Update docs and tests. ```dart colorScheme: ColorScheme.fromSeed(seedColor: Colors.red).copyWith( onSurface: Colors.yellow, onSurfaceVariant: Colors.green, ), ``` ### Before  ### After 
This commit is contained in:
@@ -397,8 +397,10 @@ md.comp.list.list-item.pressed.leading-icon.icon.color,
|
||||
md.comp.list.list-item.pressed.state-layer.color,
|
||||
md.comp.list.list-item.pressed.state-layer.opacity,
|
||||
md.comp.list.list-item.selected.trailing-icon.color,
|
||||
md.comp.list.list-item.supporting-text.color,
|
||||
md.comp.list.list-item.supporting-text.text-style,
|
||||
md.comp.list.list-item.trailing-icon.color,
|
||||
md.comp.list.list-item.trailing-supporting-text.color,
|
||||
md.comp.list.list-item.trailing-supporting-text.text-style,
|
||||
md.comp.menu.container.color,
|
||||
md.comp.menu.container.elevation,
|
||||
|
||||
|
@@ -10,6 +10,8 @@ class ListTileTemplate extends TokenTemplate {
|
||||
super.textThemePrefix = '_textTheme.',
|
||||
});
|
||||
|
||||
static const String tokenGroup = 'md.comp.list.list-item';
|
||||
|
||||
@override
|
||||
String generate() => '''
|
||||
class _${blockName}DefaultsM3 extends ListTileThemeData {
|
||||
@@ -18,7 +20,7 @@ class _${blockName}DefaultsM3 extends ListTileThemeData {
|
||||
contentPadding: const EdgeInsetsDirectional.only(start: 16.0, end: 24.0),
|
||||
minLeadingWidth: 24,
|
||||
minVerticalPadding: 8,
|
||||
shape: ${shape("md.comp.list.list-item.container")},
|
||||
shape: ${shape("$tokenGroup.container")},
|
||||
);
|
||||
|
||||
final BuildContext context;
|
||||
@@ -30,19 +32,19 @@ class _${blockName}DefaultsM3 extends ListTileThemeData {
|
||||
Color? get tileColor => Colors.transparent;
|
||||
|
||||
@override
|
||||
TextStyle? get titleTextStyle => ${textStyle("md.comp.list.list-item.label-text")};
|
||||
TextStyle? get titleTextStyle => ${textStyle("$tokenGroup.label-text")}!.copyWith(color: ${componentColor('$tokenGroup.label-text')});
|
||||
|
||||
@override
|
||||
TextStyle? get subtitleTextStyle => ${textStyle("md.comp.list.list-item.supporting-text")};
|
||||
TextStyle? get subtitleTextStyle => ${textStyle("$tokenGroup.supporting-text")}!.copyWith(color: ${componentColor('$tokenGroup.supporting-text')});
|
||||
|
||||
@override
|
||||
TextStyle? get leadingAndTrailingTextStyle => ${textStyle("md.comp.list.list-item.trailing-supporting-text")};
|
||||
TextStyle? get leadingAndTrailingTextStyle => ${textStyle("$tokenGroup.trailing-supporting-text")}!.copyWith(color: ${componentColor('$tokenGroup.trailing-supporting-text')});
|
||||
|
||||
@override
|
||||
Color? get selectedColor => ${componentColor('md.comp.list.list-item.selected.trailing-icon')};
|
||||
Color? get selectedColor => ${componentColor('$tokenGroup.selected.trailing-icon')};
|
||||
|
||||
@override
|
||||
Color? get iconColor => ${componentColor('md.comp.list.list-item.trailing-icon')};
|
||||
Color? get iconColor => ${componentColor('$tokenGroup.trailing-icon')};
|
||||
}
|
||||
''';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user