Skip to content

Commit 05aaa04

Browse files
[material_ui] Migrate M3 Typography template to use new gen_defaults (flutter#13074)
Work toward flutter/flutter#187899. Fixes flutter/flutter#188440 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 314537c commit 05aaa04

6 files changed

Lines changed: 122 additions & 179 deletions

File tree

packages/material_ui/tool/gen_defaults/temporarily_excluded/generated/typography_defaults.g.dart renamed to packages/material_ui/lib/src/generated/typography_defaults_m3.g.dart

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

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 '../typography.dart';
9+
510
abstract final class _M3Typography {
611
static const TextTheme englishLike = TextTheme(
712
displayLarge: TextStyle(

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

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import 'color_scheme.dart';
1414
import 'colors.dart';
1515
import 'text_theme.dart';
1616

17+
part 'generated/typography_defaults_m3.g.dart';
18+
1719
// Examples can assume:
1820
// late TargetPlatform platform;
1921

@@ -2083,70 +2085,3 @@ class Typography with Diagnosticable {
20832085
/// so this is just here to be consistent with the API.
20842086
static const TextTheme tall2021 = _M3Typography.tall;
20852087
}
2086-
2087-
// BEGIN GENERATED TOKEN PROPERTIES - Typography
2088-
2089-
// Do not edit by hand. The code between the "BEGIN GENERATED" and
2090-
// "END GENERATED" comments are generated from data in the Material
2091-
// Design token database by the script:
2092-
// dev/tools/gen_defaults/bin/gen_defaults.dart.
2093-
2094-
// dart format off
2095-
abstract final class _M3Typography {
2096-
static const TextTheme englishLike = TextTheme(
2097-
displayLarge: TextStyle(debugLabel: 'englishLike displayLarge 2021', inherit: false, fontSize: 57.0, fontWeight: FontWeight.w400, letterSpacing: -0.25, height: 1.12, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2098-
displayMedium: TextStyle(debugLabel: 'englishLike displayMedium 2021', inherit: false, fontSize: 45.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.16, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2099-
displaySmall: TextStyle(debugLabel: 'englishLike displaySmall 2021', inherit: false, fontSize: 36.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.22, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2100-
headlineLarge: TextStyle(debugLabel: 'englishLike headlineLarge 2021', inherit: false, fontSize: 32.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.25, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2101-
headlineMedium: TextStyle(debugLabel: 'englishLike headlineMedium 2021', inherit: false, fontSize: 28.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.29, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2102-
headlineSmall: TextStyle(debugLabel: 'englishLike headlineSmall 2021', inherit: false, fontSize: 24.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.33, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2103-
titleLarge: TextStyle(debugLabel: 'englishLike titleLarge 2021', inherit: false, fontSize: 22.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.27, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2104-
titleMedium: TextStyle(debugLabel: 'englishLike titleMedium 2021', inherit: false, fontSize: 16.0, fontWeight: FontWeight.w500, letterSpacing: 0.15, height: 1.50, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2105-
titleSmall: TextStyle(debugLabel: 'englishLike titleSmall 2021', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w500, letterSpacing: 0.1, height: 1.43, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2106-
labelLarge: TextStyle(debugLabel: 'englishLike labelLarge 2021', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w500, letterSpacing: 0.1, height: 1.43, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2107-
labelMedium: TextStyle(debugLabel: 'englishLike labelMedium 2021', inherit: false, fontSize: 12.0, fontWeight: FontWeight.w500, letterSpacing: 0.5, height: 1.33, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2108-
labelSmall: TextStyle(debugLabel: 'englishLike labelSmall 2021', inherit: false, fontSize: 11.0, fontWeight: FontWeight.w500, letterSpacing: 0.5, height: 1.45, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2109-
bodyLarge: TextStyle(debugLabel: 'englishLike bodyLarge 2021', inherit: false, fontSize: 16.0, fontWeight: FontWeight.w400, letterSpacing: 0.5, height: 1.50, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2110-
bodyMedium: TextStyle(debugLabel: 'englishLike bodyMedium 2021', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w400, letterSpacing: 0.25, height: 1.43, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2111-
bodySmall: TextStyle(debugLabel: 'englishLike bodySmall 2021', inherit: false, fontSize: 12.0, fontWeight: FontWeight.w400, letterSpacing: 0.4, height: 1.33, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2112-
);
2113-
2114-
static const TextTheme dense = TextTheme(
2115-
displayLarge: TextStyle(debugLabel: 'dense displayLarge 2021', inherit: false, fontSize: 57.0, fontWeight: FontWeight.w400, letterSpacing: -0.25, height: 1.12, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even),
2116-
displayMedium: TextStyle(debugLabel: 'dense displayMedium 2021', inherit: false, fontSize: 45.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.16, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even),
2117-
displaySmall: TextStyle(debugLabel: 'dense displaySmall 2021', inherit: false, fontSize: 36.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.22, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even),
2118-
headlineLarge: TextStyle(debugLabel: 'dense headlineLarge 2021', inherit: false, fontSize: 32.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.25, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even),
2119-
headlineMedium: TextStyle(debugLabel: 'dense headlineMedium 2021', inherit: false, fontSize: 28.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.29, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even),
2120-
headlineSmall: TextStyle(debugLabel: 'dense headlineSmall 2021', inherit: false, fontSize: 24.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.33, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even),
2121-
titleLarge: TextStyle(debugLabel: 'dense titleLarge 2021', inherit: false, fontSize: 22.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.27, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even),
2122-
titleMedium: TextStyle(debugLabel: 'dense titleMedium 2021', inherit: false, fontSize: 16.0, fontWeight: FontWeight.w500, letterSpacing: 0.15, height: 1.50, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even),
2123-
titleSmall: TextStyle(debugLabel: 'dense titleSmall 2021', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w500, letterSpacing: 0.1, height: 1.43, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even),
2124-
labelLarge: TextStyle(debugLabel: 'dense labelLarge 2021', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w500, letterSpacing: 0.1, height: 1.43, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even),
2125-
labelMedium: TextStyle(debugLabel: 'dense labelMedium 2021', inherit: false, fontSize: 12.0, fontWeight: FontWeight.w500, letterSpacing: 0.5, height: 1.33, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even),
2126-
labelSmall: TextStyle(debugLabel: 'dense labelSmall 2021', inherit: false, fontSize: 11.0, fontWeight: FontWeight.w500, letterSpacing: 0.5, height: 1.45, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even),
2127-
bodyLarge: TextStyle(debugLabel: 'dense bodyLarge 2021', inherit: false, fontSize: 16.0, fontWeight: FontWeight.w400, letterSpacing: 0.5, height: 1.50, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even),
2128-
bodyMedium: TextStyle(debugLabel: 'dense bodyMedium 2021', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w400, letterSpacing: 0.25, height: 1.43, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even),
2129-
bodySmall: TextStyle(debugLabel: 'dense bodySmall 2021', inherit: false, fontSize: 12.0, fontWeight: FontWeight.w400, letterSpacing: 0.4, height: 1.33, textBaseline: TextBaseline.ideographic, leadingDistribution: TextLeadingDistribution.even),
2130-
);
2131-
2132-
static const TextTheme tall = TextTheme(
2133-
displayLarge: TextStyle(debugLabel: 'tall displayLarge 2021', inherit: false, fontSize: 57.0, fontWeight: FontWeight.w400, letterSpacing: -0.25, height: 1.12, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2134-
displayMedium: TextStyle(debugLabel: 'tall displayMedium 2021', inherit: false, fontSize: 45.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.16, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2135-
displaySmall: TextStyle(debugLabel: 'tall displaySmall 2021', inherit: false, fontSize: 36.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.22, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2136-
headlineLarge: TextStyle(debugLabel: 'tall headlineLarge 2021', inherit: false, fontSize: 32.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.25, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2137-
headlineMedium: TextStyle(debugLabel: 'tall headlineMedium 2021', inherit: false, fontSize: 28.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.29, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2138-
headlineSmall: TextStyle(debugLabel: 'tall headlineSmall 2021', inherit: false, fontSize: 24.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.33, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2139-
titleLarge: TextStyle(debugLabel: 'tall titleLarge 2021', inherit: false, fontSize: 22.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.27, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2140-
titleMedium: TextStyle(debugLabel: 'tall titleMedium 2021', inherit: false, fontSize: 16.0, fontWeight: FontWeight.w500, letterSpacing: 0.15, height: 1.50, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2141-
titleSmall: TextStyle(debugLabel: 'tall titleSmall 2021', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w500, letterSpacing: 0.1, height: 1.43, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2142-
labelLarge: TextStyle(debugLabel: 'tall labelLarge 2021', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w500, letterSpacing: 0.1, height: 1.43, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2143-
labelMedium: TextStyle(debugLabel: 'tall labelMedium 2021', inherit: false, fontSize: 12.0, fontWeight: FontWeight.w500, letterSpacing: 0.5, height: 1.33, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2144-
labelSmall: TextStyle(debugLabel: 'tall labelSmall 2021', inherit: false, fontSize: 11.0, fontWeight: FontWeight.w500, letterSpacing: 0.5, height: 1.45, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2145-
bodyLarge: TextStyle(debugLabel: 'tall bodyLarge 2021', inherit: false, fontSize: 16.0, fontWeight: FontWeight.w400, letterSpacing: 0.5, height: 1.50, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2146-
bodyMedium: TextStyle(debugLabel: 'tall bodyMedium 2021', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w400, letterSpacing: 0.25, height: 1.43, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2147-
bodySmall: TextStyle(debugLabel: 'tall bodySmall 2021', inherit: false, fontSize: 12.0, fontWeight: FontWeight.w400, letterSpacing: 0.4, height: 1.33, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even),
2148-
);
2149-
}
2150-
// dart format on
2151-
2152-
// END GENERATED TOKEN PROPERTIES - Typography

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import '../templates/input_decorator_template.dart';
3636
import '../templates/list_tile_template.dart';
3737
import '../templates/menu_template.dart';
3838
import '../templates/motion_template.dart';
39-
4039
// import '../templates/navigation_bar_template.dart';
4140
// import '../templates/navigation_drawer_template.dart';
4241
// import '../templates/navigation_rail_template.dart';
@@ -49,13 +48,12 @@ import '../templates/motion_template.dart';
4948
// import '../templates/segmented_button_template.dart';
5049
// import '../templates/slider_template.dart';
5150
import '../templates/snackbar_template.dart';
52-
5351
// import '../templates/surface_tint_template.dart';
5452
// import '../templates/switch_template.dart';
5553
// import '../templates/tabs_template.dart';
5654
// import '../templates/text_field_template.dart';
5755
// import '../templates/time_picker_template.dart';
58-
// import '../templates/typography_template.dart';
56+
import '../templates/typography_template.dart';
5957

6058
Future<void> main(List<String> args) async {
6159
// Parse arguments
@@ -117,5 +115,5 @@ Future<void> main(List<String> args) async {
117115
// const TabsTemplateM3().generateFile(verbose: verbose);
118116
// const TextFieldTemplateM3().generateFile(verbose: verbose);
119117
// const TimePickerTemplateM3().generateFile(verbose: verbose);
120-
// const TypographyTemplateM3().generateFile(verbose: verbose);
118+
const TypographyTemplateM3().generateFile(verbose: verbose);
121119
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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/typescale.dart';
6+
import '../data/typescale_struct.dart';
7+
import 'template.dart';
8+
9+
class TypographyTemplateM3 extends TokenTemplateM3 {
10+
const TypographyTemplateM3();
11+
12+
@override
13+
String get name => 'Typography';
14+
15+
@override
16+
String get parentFilePath => 'typography.dart';
17+
18+
@override
19+
String get className => '_M3Typography';
20+
21+
static const List<(String, TypescaleStruct)> _textStyles = <(String, TypescaleStruct)>[
22+
('displayLarge', TokenTypescale.displayLarge),
23+
('displayMedium', TokenTypescale.displayMedium),
24+
('displaySmall', TokenTypescale.displaySmall),
25+
('headlineLarge', TokenTypescale.headlineLarge),
26+
('headlineMedium', TokenTypescale.headlineMedium),
27+
('headlineSmall', TokenTypescale.headlineSmall),
28+
('titleLarge', TokenTypescale.titleLarge),
29+
('titleMedium', TokenTypescale.titleMedium),
30+
('titleSmall', TokenTypescale.titleSmall),
31+
('labelLarge', TokenTypescale.labelLarge),
32+
('labelMedium', TokenTypescale.labelMedium),
33+
('labelSmall', TokenTypescale.labelSmall),
34+
('bodyLarge', TokenTypescale.bodyLarge),
35+
('bodyMedium', TokenTypescale.bodyMedium),
36+
('bodySmall', TokenTypescale.bodySmall),
37+
];
38+
39+
@override
40+
String generateContents(String className) =>
41+
'''
42+
abstract final class $className {
43+
${_textTheme('englishLike', 'alphabetic')}
44+
45+
${_textTheme('dense', 'ideographic')}
46+
47+
${_textTheme('tall', 'alphabetic')}
48+
}
49+
''';
50+
51+
String _textTheme(String name, String baseline) {
52+
final theme = StringBuffer('static const TextTheme $name = TextTheme(\n');
53+
for (final (String styleName, TypescaleStruct token) in _textStyles) {
54+
theme.writeln(' $styleName: ${_textStyleDef(token, '$name $styleName 2021', baseline)},');
55+
}
56+
theme.write(' );');
57+
return theme.toString();
58+
}
59+
60+
String _textStyleDef(TypescaleStruct typescaleStruct, String debugLabel, String baseline) {
61+
final style = StringBuffer("TextStyle(debugLabel: '$debugLabel'");
62+
style.write(', inherit: false');
63+
style.write(', fontSize: ${_fontSize(typescaleStruct)}');
64+
style.write(', fontWeight: ${_fontWeight(typescaleStruct)}');
65+
style.write(', letterSpacing: ${_fontSpacing(typescaleStruct)}');
66+
style.write(', height: ${_fontHeight(typescaleStruct)}');
67+
style.write(', textBaseline: TextBaseline.$baseline');
68+
style.write(', leadingDistribution: TextLeadingDistribution.even');
69+
style.write(')');
70+
return style.toString();
71+
}
72+
73+
String _fontSize(TypescaleStruct typescaleStruct) {
74+
return number(typescaleStruct.fontSize);
75+
}
76+
77+
String _fontWeight(TypescaleStruct typescaleStruct) {
78+
final double weightValue = typescaleStruct.fontWeight;
79+
return 'FontWeight.w${weightValue.toInt()}';
80+
}
81+
82+
String _fontSpacing(TypescaleStruct typescaleStruct) {
83+
return number(typescaleStruct.letterSpacing);
84+
}
85+
86+
String _fontHeight(TypescaleStruct typescaleStruct) {
87+
final double size = typescaleStruct.fontSize;
88+
final double lineHeight = typescaleStruct.lineHeight;
89+
return (lineHeight / size).toStringAsFixed(2);
90+
}
91+
}

0 commit comments

Comments
 (0)