Skip to content

Commit 6f11020

Browse files
authored
[material_ui] Migrate M3 ListTile template to use new gen_defaults (flutter#13056)
Work toward flutter/flutter#187899. Fixes flutter/flutter#188420. This PR migrates the M3 ListTile defaults template to use the new gen_defaults in material_ui. The generated defaults remain unchanged. ## Pre-Review Checklist
1 parent 441bcbc commit 6f11020

6 files changed

Lines changed: 88 additions & 108 deletions

File tree

packages/material_ui/tool/gen_defaults/temporarily_excluded/generated/list_tile_defaults.g.dart renamed to packages/material_ui/lib/src/generated/list_tile_defaults_m3.g.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
class _LisTileDefaultsM3 extends ListTileThemeData {
6-
_LisTileDefaultsM3(this.context)
5+
// Do not edit by hand. The code is generated from data in the Material
6+
// Design token database by the script:
7+
// packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart.
8+
part of '../list_tile.dart';
9+
10+
class _ListTileDefaultsM3 extends ListTileThemeData {
11+
_ListTileDefaultsM3(this.context)
712
: super(
813
contentPadding: const EdgeInsetsDirectional.only(start: 16.0, end: 24.0),
9-
minLeadingWidth: 24,
14+
minLeadingWidth: 24.0,
1015
minVerticalPadding: 8,
1116
shape: const RoundedRectangleBorder(),
1217
);

‎packages/material_ui/lib/src/list_tile.dart‎

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import 'text_theme.dart';
3737
import 'theme.dart';
3838
import 'theme_data.dart';
3939

40+
part 'generated/list_tile_defaults_m3.g.dart';
41+
4042
// Examples can assume:
4143
// int _act = 1;
4244

@@ -884,7 +886,7 @@ class ListTile extends StatelessWidget {
884886
final ListTileStyle listTileStyle =
885887
style ?? tileTheme.style ?? theme.listTileTheme.style ?? ListTileStyle.list;
886888
final ListTileThemeData defaults = theme.useMaterial3
887-
? _LisTileDefaultsM3(context)
889+
? _ListTileDefaultsM3(context)
888890
: _LisTileDefaultsM2(context, listTileStyle);
889891

890892
final Color backgroundColor =
@@ -1871,47 +1873,3 @@ class _LisTileDefaultsM2 extends ListTileThemeData {
18711873
Brightness.dark => null,
18721874
};
18731875
}
1874-
1875-
// BEGIN GENERATED TOKEN PROPERTIES - LisTile
1876-
1877-
// Do not edit by hand. The code between the "BEGIN GENERATED" and
1878-
// "END GENERATED" comments are generated from data in the Material
1879-
// Design token database by the script:
1880-
// dev/tools/gen_defaults/bin/gen_defaults.dart.
1881-
1882-
// dart format off
1883-
class _LisTileDefaultsM3 extends ListTileThemeData {
1884-
_LisTileDefaultsM3(this.context)
1885-
: super(
1886-
contentPadding: const EdgeInsetsDirectional.only(start: 16.0, end: 24.0),
1887-
minLeadingWidth: 24,
1888-
minVerticalPadding: 8,
1889-
shape: const RoundedRectangleBorder(),
1890-
);
1891-
1892-
final BuildContext context;
1893-
late final ThemeData _theme = Theme.of(context);
1894-
late final ColorScheme _colors = _theme.colorScheme;
1895-
late final TextTheme _textTheme = _theme.textTheme;
1896-
1897-
@override
1898-
Color? get tileColor => Colors.transparent;
1899-
1900-
@override
1901-
TextStyle? get titleTextStyle => _textTheme.bodyLarge!.copyWith(color: _colors.onSurface);
1902-
1903-
@override
1904-
TextStyle? get subtitleTextStyle => _textTheme.bodyMedium!.copyWith(color: _colors.onSurfaceVariant);
1905-
1906-
@override
1907-
TextStyle? get leadingAndTrailingTextStyle => _textTheme.labelSmall!.copyWith(color: _colors.onSurfaceVariant);
1908-
1909-
@override
1910-
Color? get selectedColor => _colors.primary;
1911-
1912-
@override
1913-
Color? get iconColor => _colors.onSurfaceVariant;
1914-
}
1915-
// dart format on
1916-
1917-
// END GENERATED TOKEN PROPERTIES - LisTile

‎packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ import '../templates/fab_template.dart';
3232
import '../templates/filter_chip_template.dart';
3333
import '../templates/icon_button_template.dart';
3434
import '../templates/input_chip_template.dart';
35-
3635
import '../templates/input_decorator_template.dart';
36+
import '../templates/list_tile_template.dart';
3737

38-
// import '../templates/list_tile_template.dart';
3938
// import '../templates/menu_template.dart';
4039
// import '../templates/motion_template.dart';
4140
// import '../templates/navigation_bar_template.dart';
@@ -97,7 +96,7 @@ Future<void> main(List<String> args) async {
9796
const IconButtonTemplateM3E('Outlined Icon Button').generateFile(verbose: verbose);
9897
const InputChipTemplateM3().generateFile(verbose: verbose);
9998
const InputDecoratorTemplateM3().generateFile(verbose: verbose);
100-
// const ListTileTemplateM3().generateFile(verbose: verbose);
99+
const ListTileTemplateM3().generateFile(verbose: verbose);
101100
// const MenuTemplateM3().generateFile(verbose: verbose);
102101
// const MotionTemplateM3().generateFile(verbose: verbose);
103102
// const NavigationBarTemplateM3().generateFile(verbose: verbose);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2013 The Flutter Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import '../data/color_role.dart';
6+
import '../data/list.dart';
7+
import 'template.dart';
8+
9+
class ListTileTemplateM3 extends TokenTemplateM3 {
10+
const ListTileTemplateM3();
11+
12+
@override
13+
String get name => 'List Tile';
14+
15+
@override
16+
String get parentFilePath => 'list_tile.dart';
17+
18+
// The selected trailing-icon token differs from the existing ListTile
19+
// default. Preserve the existing color during this template migration.
20+
static const TokenColorRole _legacySelectedColor = TokenColorRole.primary;
21+
22+
@override
23+
String get className => '_ListTileDefaultsM3';
24+
25+
@override
26+
String generateContents(String className) =>
27+
'''
28+
class $className extends ListTileThemeData {
29+
$className(this.context)
30+
: super(
31+
contentPadding: const EdgeInsetsDirectional.only(start: 16.0, end: 24.0),
32+
minLeadingWidth: ${TokenList.listItemLeadingIconSize},
33+
minVerticalPadding: 8,
34+
shape: ${shape(TokenList.listItemContainerShape)},
35+
);
36+
37+
final BuildContext context;
38+
late final ThemeData _theme = Theme.of(context);
39+
late final ColorScheme _colors = _theme.colorScheme;
40+
late final TextTheme _textTheme = _theme.textTheme;
41+
42+
@override
43+
Color? get tileColor => Colors.transparent;
44+
45+
@override
46+
TextStyle? get titleTextStyle => ${textStyle(TokenList.listItemLabelTextType, '_textTheme')}!.copyWith(color: ${color(TokenList.listItemLabelTextColor)});
47+
48+
@override
49+
TextStyle? get subtitleTextStyle => ${textStyle(TokenList.listItemSupportingTextType, '_textTheme')}!.copyWith(color: ${color(TokenList.listItemSupportingTextColor)});
50+
51+
@override
52+
TextStyle? get leadingAndTrailingTextStyle => ${textStyle(TokenList.listItemTrailingSupportingTextType, '_textTheme')}!.copyWith(color: ${color(TokenList.listItemTrailingSupportingTextColor)});
53+
54+
@override
55+
Color? get selectedColor => ${color(_legacySelectedColor)};
56+
57+
@override
58+
Color? get iconColor => ${color(TokenList.listItemTrailingIconColor)};
59+
}
60+
''';
61+
}

‎packages/material_ui/tool/gen_defaults/temporarily_excluded/templates/list_tile_template.dart‎

Lines changed: 0 additions & 54 deletions
This file was deleted.

‎packages/material_ui/tool/gen_defaults/test/gen_defaults_test.dart‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import '../templates/filter_chip_template.dart';
3030
import '../templates/icon_button_template.dart' as icon_button;
3131
import '../templates/input_chip_template.dart';
3232
import '../templates/input_decorator_template.dart';
33-
// import '../templates/list_tile_template.dart';
33+
import '../templates/list_tile_template.dart';
3434
// import '../templates/menu_template.dart';
3535
// import '../templates/motion_template.dart';
3636
// import '../templates/navigation_bar_template.dart';
@@ -695,8 +695,19 @@ void main() {
695695
});
696696

697697
test('ListTileTemplateM3 emits M3 ListTile defaults from tokens', () {
698-
// Intentionally empty, will be implemented during migration. See:
699-
// https://github.com/flutter/flutter/issues/187899
698+
const template = ListTileTemplateM3();
699+
final String contents = _generateContents(template);
700+
expect(template.className, '_ListTileDefaultsM3');
701+
expect(template.outputFileName, 'list_tile_defaults_m3.g.dart');
702+
expect(contents, contains('contentPadding: const EdgeInsetsDirectional.only'));
703+
expect(contents, contains('minLeadingWidth: 24.0'));
704+
expect(
705+
contents,
706+
contains(
707+
'TextStyle? get titleTextStyle => _textTheme.bodyLarge!.copyWith(color: _colors.onSurface)',
708+
),
709+
);
710+
expect(contents, contains('Color? get selectedColor => _colors.primary;'));
700711
});
701712

702713
test('MenuTemplateM3 emits M3 Menu defaults from tokens', () {

0 commit comments

Comments
 (0)