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

![Screenshot 2023-06-09 at 17 47 04](https://github.com/flutter/flutter/assets/48603081/c0130371-3c7c-428c-bb57-504822cf64b5)

### After

![Screenshot 2023-06-09 at 17 46 17](https://github.com/flutter/flutter/assets/48603081/3b4d6f8c-7fdd-4546-a6f0-00dd34cb5a96)
This commit is contained in:
Taha Tesser
2023-06-12 17:52:06 +03:00
committed by GitHub
parent 6f2118be77
commit ca5aa2329a
4 changed files with 27 additions and 19 deletions

View File

@@ -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,
1 Versions used, v0_162, v0_158
397 md.comp.list.list-item.pressed.state-layer.color,
398 md.comp.list.list-item.pressed.state-layer.opacity,
399 md.comp.list.list-item.selected.trailing-icon.color,
400 md.comp.list.list-item.supporting-text.color,
401 md.comp.list.list-item.supporting-text.text-style,
402 md.comp.list.list-item.trailing-icon.color,
403 md.comp.list.list-item.trailing-supporting-text.color,
404 md.comp.list.list-item.trailing-supporting-text.text-style,
405 md.comp.menu.container.color,
406 md.comp.menu.container.elevation,

View File

@@ -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')};
}
''';
}