Auto-format Framework (#160545)

This auto-formats all *.dart files in the repository outside of the
`engine` subdirectory and enforces that these files stay formatted with
a presubmit check.

**Reviewers:** Please carefully review all the commits except for the
one titled "formatted". The "formatted" commit was auto-generated by
running `dev/tools/format.sh -a -f`. The other commits were hand-crafted
to prepare the repo for the formatting change. I recommend reviewing the
commits one-by-one via the "Commits" tab and avoiding Github's "Files
changed" tab as it will likely slow down your browser because of the
size of this PR.

---------

Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
This commit is contained in:
Michael Goderbauer
2024-12-19 12:06:21 -08:00
committed by GitHub
parent 8e0993eda8
commit 5491c8c146
4411 changed files with 455108 additions and 415991 deletions

View File

@@ -5,9 +5,12 @@
import 'template.dart';
class ActionChipTemplate extends TokenTemplate {
const ActionChipTemplate(super.blockName, super.fileName, super.tokens, {
const ActionChipTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
super.textThemePrefix = '_textTheme.'
super.textThemePrefix = '_textTheme.',
});
static const String tokenGroup = 'md.comp.assist-chip';

View File

@@ -6,10 +6,7 @@ import 'template.dart';
class AppBarTemplate extends TokenTemplate {
const AppBarTemplate(super.blockName, super.fileName, super.tokens)
: super(
colorSchemePrefix: '_colors.',
textThemePrefix: '_textTheme.',
);
: super(colorSchemePrefix: '_colors.', textThemePrefix: '_textTheme.');
@override
String generate() => '''

View File

@@ -5,7 +5,10 @@
import 'template.dart';
class BadgeTemplate extends TokenTemplate {
const BadgeTemplate(super.blockName, super.fileName, super.tokens, {
const BadgeTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
});

View File

@@ -5,9 +5,12 @@
import 'template.dart';
class BannerTemplate extends TokenTemplate {
const BannerTemplate(super.blockName, super.fileName, super.tokens, {
const BannerTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
super.textThemePrefix = '_textTheme.'
super.textThemePrefix = '_textTheme.',
});
@override

View File

@@ -5,7 +5,10 @@
import 'template.dart';
class BottomAppBarTemplate extends TokenTemplate {
const BottomAppBarTemplate(super.blockName, super.fileName, super.tokens, {
const BottomAppBarTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
});

View File

@@ -5,7 +5,11 @@
import 'template.dart';
class ButtonTemplate extends TokenTemplate {
const ButtonTemplate(this.tokenGroup, super.blockName, super.fileName, super.tokens, {
const ButtonTemplate(
this.tokenGroup,
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
});

View File

@@ -5,7 +5,11 @@
import 'template.dart';
class CardTemplate extends TokenTemplate {
const CardTemplate(this.tokenGroup, super.blockName, super.fileName, super.tokens, {
const CardTemplate(
this.tokenGroup,
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
});

View File

@@ -5,7 +5,10 @@
import 'template.dart';
class CheckboxTemplate extends TokenTemplate {
const CheckboxTemplate(super.blockName, super.fileName, super.tokens, {
const CheckboxTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
});

View File

@@ -5,9 +5,12 @@
import 'template.dart';
class ChipTemplate extends TokenTemplate {
const ChipTemplate(super.blockName, super.fileName, super.tokens, {
const ChipTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
super.textThemePrefix = '_textTheme.'
super.textThemePrefix = '_textTheme.',
});
static const String tokenGroup = 'md.comp.filter-chip';

View File

@@ -6,7 +6,13 @@ import 'template.dart';
import 'token_logger.dart';
class ColorSchemeTemplate extends TokenTemplate {
ColorSchemeTemplate(this._colorTokensLight, this._colorTokensDark, super.blockName, super.fileName, super.tokens);
ColorSchemeTemplate(
this._colorTokensLight,
this._colorTokensDark,
super.blockName,
super.fileName,
super.tokens,
);
// Map of light color scheme token data from tokens.
final Map<String, dynamic> _colorTokensLight;

View File

@@ -5,9 +5,12 @@
import 'template.dart';
class DatePickerTemplate extends TokenTemplate {
const DatePickerTemplate(super.blockName, super.fileName, super.tokens, {
const DatePickerTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
super.textThemePrefix = '_textTheme.'
super.textThemePrefix = '_textTheme.',
});
String _layerOpacity(String layerToken) {
@@ -26,9 +29,9 @@ class DatePickerTemplate extends TokenTemplate {
String _stateColor(String componentToken, String? type, String state) {
final String baseColor = color(
type != null
? '$componentToken.$type.$state.state-layer.color'
: '$componentToken.$state.state-layer.color',
''
? '$componentToken.$type.$state.state-layer.color'
: '$componentToken.$state.state-layer.color',
'',
);
if (baseColor.isEmpty) {
return 'null';

View File

@@ -5,9 +5,12 @@
import 'template.dart';
class DialogTemplate extends TokenTemplate {
const DialogTemplate(super.blockName, super.fileName, super.tokens, {
const DialogTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
super.textThemePrefix = '_textTheme.'
super.textThemePrefix = '_textTheme.',
});
@override

View File

@@ -5,7 +5,10 @@
import 'template.dart';
class ExpansionTileTemplate extends TokenTemplate {
const ExpansionTileTemplate(super.blockName, super.fileName, super.tokens, {
const ExpansionTileTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
});

View File

@@ -5,7 +5,10 @@
import 'template.dart';
class FABTemplate extends TokenTemplate {
const FABTemplate(super.blockName, super.fileName, super.tokens, {
const FABTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
super.textThemePrefix = '_textTheme.',
});

View File

@@ -5,9 +5,12 @@
import 'template.dart';
class FilterChipTemplate extends TokenTemplate {
const FilterChipTemplate(super.blockName, super.fileName, super.tokens, {
const FilterChipTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
super.textThemePrefix = '_textTheme.'
super.textThemePrefix = '_textTheme.',
});
static const String tokenGroup = 'md.comp.filter-chip';

View File

@@ -5,7 +5,11 @@
import 'template.dart';
class IconButtonTemplate extends TokenTemplate {
const IconButtonTemplate(this.tokenGroup, super.blockName, super.fileName, super.tokens, {
const IconButtonTemplate(
this.tokenGroup,
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
});
@@ -185,7 +189,8 @@ class IconButtonTemplate extends TokenTemplate {
}
String _minimumSize() {
if (tokenAvailable('$tokenGroup.container.height') && tokenAvailable('$tokenGroup.container.width')) {
if (tokenAvailable('$tokenGroup.container.height') &&
tokenAvailable('$tokenGroup.container.width')) {
return '''
const MaterialStatePropertyAll<Size>(Size(${getToken('$tokenGroup.container.width')}, ${getToken('$tokenGroup.container.height')}))''';
@@ -313,5 +318,4 @@ class _${blockName}DefaultsM3 extends ButtonStyle {
InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory;
}
''';
}

View File

@@ -5,9 +5,12 @@
import 'template.dart';
class InputChipTemplate extends TokenTemplate {
const InputChipTemplate(super.blockName, super.fileName, super.tokens, {
const InputChipTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
super.textThemePrefix = '_textTheme.'
super.textThemePrefix = '_textTheme.',
});
static const String tokenGroup = 'md.comp.input-chip';

View File

@@ -5,9 +5,12 @@
import 'template.dart';
class InputDecoratorTemplate extends TokenTemplate {
const InputDecoratorTemplate(super.blockName, super.fileName, super.tokens, {
const InputDecoratorTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
super.textThemePrefix = '_textTheme.'
super.textThemePrefix = '_textTheme.',
});
@override
@@ -54,7 +57,7 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme {
}
if (states.contains(MaterialState.error)) {
if (states.contains(MaterialState.focused)) {
return ${mergedBorder('md.comp.filled-text-field.error.focus.active-indicator','md.comp.filled-text-field.focus.active-indicator')};
return ${mergedBorder('md.comp.filled-text-field.error.focus.active-indicator', 'md.comp.filled-text-field.focus.active-indicator')};
}
if (states.contains(MaterialState.hovered)) {
return ${border('md.comp.filled-text-field.error.hover.active-indicator')};
@@ -77,7 +80,7 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme {
}
if (states.contains(MaterialState.error)) {
if (states.contains(MaterialState.focused)) {
return ${mergedBorder('md.comp.outlined-text-field.error.focus.outline','md.comp.outlined-text-field.focus.outline')};
return ${mergedBorder('md.comp.outlined-text-field.error.focus.outline', 'md.comp.outlined-text-field.focus.outline')};
}
if (states.contains(MaterialState.hovered)) {
return ${border('md.comp.outlined-text-field.error.hover.outline')};
@@ -221,15 +224,17 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme {
/// Generate a [BorderSide] for the given components.
String mergedBorder(String componentToken1, String componentToken2) {
final String borderColor = componentColor(componentToken1)!= 'null'
? componentColor(componentToken1)
: componentColor(componentToken2);
final double width = (
getToken('$componentToken1.width', optional: true) ??
getToken('$componentToken1.height', optional: true) ??
getToken('$componentToken2.width', optional: true) ??
getToken('$componentToken2.height', optional: true) ??
1.0) as double;
final String borderColor =
componentColor(componentToken1) != 'null'
? componentColor(componentToken1)
: componentColor(componentToken2);
final double width =
(getToken('$componentToken1.width', optional: true) ??
getToken('$componentToken1.height', optional: true) ??
getToken('$componentToken2.width', optional: true) ??
getToken('$componentToken2.height', optional: true) ??
1.0)
as double;
return 'BorderSide(color: $borderColor${width != 1.0 ? ", width: $width" : ""})';
}
}

View File

@@ -5,7 +5,10 @@
import 'template.dart';
class ListTileTemplate extends TokenTemplate {
const ListTileTemplate(super.blockName, super.fileName, super.tokens, {
const ListTileTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
super.textThemePrefix = '_textTheme.',
});

View File

@@ -5,7 +5,10 @@
import 'template.dart';
class MenuTemplate extends TokenTemplate {
const MenuTemplate(super.blockName, super.fileName, super.tokens, {
const MenuTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
});
@@ -247,10 +250,7 @@ class _MenuDefaultsM3 extends MenuStyle {
@override
MaterialStateProperty<Color?>? get surfaceTintColor {
return ${componentColor('md.comp.menu.container.surface-tint-layer') == 'null'
? 'const MaterialStatePropertyAll<Color?>(Colors.transparent)'
: 'MaterialStatePropertyAll<Color?>(${componentColor('md.comp.menu.container.surface-tint-layer')})'
};
return ${componentColor('md.comp.menu.container.surface-tint-layer') == 'null' ? 'const MaterialStatePropertyAll<Color?>(Colors.transparent)' : 'MaterialStatePropertyAll<Color?>(${componentColor('md.comp.menu.container.surface-tint-layer')})'};
}
@override

View File

@@ -8,33 +8,37 @@ import 'token_logger.dart';
class MotionTemplate extends TokenTemplate {
/// Since we generate the tokens dynamically, we need to store them and log
/// them manually, instead of using [getToken].
MotionTemplate(String blockName, String fileName, this.tokens, this.tokensLogger) : super(blockName, fileName, tokens);
MotionTemplate(String blockName, String fileName, this.tokens, this.tokensLogger)
: super(blockName, fileName, tokens);
Map<String, dynamic> tokens;
TokenLogger tokensLogger;
// List of duration tokens.
late List<MapEntry<String, dynamic>> durationTokens = tokens.entries.where(
(MapEntry<String, dynamic> entry) => entry.key.contains('.duration.')
).toList()
..sort(
(MapEntry<String, dynamic> a, MapEntry<String, dynamic> b) => (a.value as double).compareTo(b.value as double)
);
late List<MapEntry<String, dynamic>> durationTokens =
tokens.entries
.where((MapEntry<String, dynamic> entry) => entry.key.contains('.duration.'))
.toList()
..sort(
(MapEntry<String, dynamic> a, MapEntry<String, dynamic> b) =>
(a.value as double).compareTo(b.value as double),
);
// List of easing curve tokens.
late List<MapEntry<String, dynamic>> easingCurveTokens = tokens.entries.where(
(MapEntry<String, dynamic> entry) => entry.key.contains('.easing.')
).toList()
..sort(
// Sort the legacy curves at the end of the list.
(MapEntry<String, dynamic> a, MapEntry<String, dynamic> b) => a.key.contains('legacy') ? 1 : a.key.compareTo(b.key)
);
late List<MapEntry<String, dynamic>> easingCurveTokens =
tokens.entries
.where((MapEntry<String, dynamic> entry) => entry.key.contains('.easing.'))
.toList()
..sort(
// Sort the legacy curves at the end of the list.
(MapEntry<String, dynamic> a, MapEntry<String, dynamic> b) =>
a.key.contains('legacy') ? 1 : a.key.compareTo(b.key),
);
String durationTokenString(String token, dynamic tokenValue) {
tokensLogger.log(token);
final String tokenName = token.split('.').last.replaceAll('-', '').replaceFirst('Ms', '');
final int milliseconds = (tokenValue as double).toInt();
return
'''
return '''
/// The $tokenName duration (${milliseconds}ms) in the Material specification.
///
/// See also:
@@ -47,11 +51,12 @@ class MotionTemplate extends TokenTemplate {
String easingCurveTokenString(String token, dynamic tokenValue) {
tokensLogger.log(token);
final String tokenName = token
.replaceFirst('md.sys.motion.easing.', '')
.replaceAllMapped(RegExp(r'[-\.](\w)'), (Match match) {
final String tokenName = token.replaceFirst('md.sys.motion.easing.', '').replaceAllMapped(
RegExp(r'[-\.](\w)'),
(Match match) {
return match.group(1)!.toUpperCase();
});
},
);
return '''
/// The $tokenName easing curve in the Material specification.
///

View File

@@ -5,7 +5,10 @@
import 'template.dart';
class NavigationBarTemplate extends TokenTemplate {
const NavigationBarTemplate(super.blockName, super.fileName, super.tokens, {
const NavigationBarTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
super.textThemePrefix = '_textTheme.',
});

View File

@@ -5,9 +5,12 @@
import 'template.dart';
class NavigationDrawerTemplate extends TokenTemplate {
const NavigationDrawerTemplate(super.blockName, super.fileName, super.tokens, {
const NavigationDrawerTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
super.textThemePrefix = '_textTheme.'
super.textThemePrefix = '_textTheme.',
});
@override

View File

@@ -5,7 +5,10 @@
import 'template.dart';
class NavigationRailTemplate extends TokenTemplate {
const NavigationRailTemplate(super.blockName, super.fileName, super.tokens, {
const NavigationRailTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
super.textThemePrefix = '_textTheme.',
});

View File

@@ -5,7 +5,10 @@
import 'template.dart';
class PopupMenuTemplate extends TokenTemplate {
const PopupMenuTemplate(super.blockName, super.fileName, super.tokens, {
const PopupMenuTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
super.textThemePrefix = '_textTheme.',
});

View File

@@ -5,7 +5,10 @@
import 'template.dart';
class ProgressIndicatorTemplate extends TokenTemplate {
const ProgressIndicatorTemplate(super.blockName, super.fileName, super.tokens, {
const ProgressIndicatorTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
});

View File

@@ -5,7 +5,10 @@
import 'template.dart';
class RadioTemplate extends TokenTemplate {
const RadioTemplate(super.blockName, super.fileName, super.tokens, {
const RadioTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
});

View File

@@ -5,13 +5,18 @@
import 'template.dart';
class SearchBarTemplate extends TokenTemplate {
const SearchBarTemplate(super.blockName, super.fileName, super.tokens, {
const SearchBarTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
super.textThemePrefix = '_textTheme.'
super.textThemePrefix = '_textTheme.',
});
String _surfaceTint() {
final String? color = colorOrTransparent('md.comp.search-bar.container.surface-tint-layer.color');
final String? color = colorOrTransparent(
'md.comp.search-bar.container.surface-tint-layer.color',
);
final String surfaceTintColor = 'MaterialStatePropertyAll<Color>($color);';
if (color == 'Colors.transparent') {
return 'const $surfaceTintColor';

View File

@@ -5,9 +5,12 @@
import 'template.dart';
class SearchViewTemplate extends TokenTemplate {
const SearchViewTemplate(super.blockName, super.fileName, super.tokens, {
const SearchViewTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
super.textThemePrefix = '_textTheme.'
super.textThemePrefix = '_textTheme.',
});
@override

View File

@@ -5,7 +5,11 @@
import 'template.dart';
class SegmentedButtonTemplate extends TokenTemplate {
const SegmentedButtonTemplate(this.tokenGroup, super.blockName, super.fileName, super.tokens, {
const SegmentedButtonTemplate(
this.tokenGroup,
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
});

View File

@@ -5,7 +5,11 @@
import 'template.dart';
class SliderTemplate extends TokenTemplate {
const SliderTemplate(this.tokenGroup, super.blockName, super.fileName, super.tokens, {
const SliderTemplate(
this.tokenGroup,
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
});

View File

@@ -6,8 +6,11 @@ import 'template.dart';
class SnackbarTemplate extends TokenTemplate {
const SnackbarTemplate(
this.tokenGroup, super.blockName, super.fileName, super.tokens, {
super.colorSchemePrefix = '_colors.'
this.tokenGroup,
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
});
final String tokenGroup;

View File

@@ -5,7 +5,10 @@
import 'template.dart';
class SwitchTemplate extends TokenTemplate {
const SwitchTemplate(super.blockName, super.fileName, super.tokens, {
const SwitchTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
});
@@ -231,5 +234,4 @@ class _SwitchConfigM3 with _SwitchConfig {
Size get switchMinSize => const Size(kMinInteractiveDimension, kMinInteractiveDimension - 8.0);
}
''';
}

View File

@@ -5,7 +5,10 @@
import 'template.dart';
class TabsTemplate extends TokenTemplate {
const TabsTemplate(super.blockName, super.fileName, super.tokens, {
const TabsTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
super.textThemePrefix = '_textTheme.',
});
@@ -160,5 +163,4 @@ class _${blockName}SecondaryDefaultsM3 extends TabBarThemeData {
static double indicatorWeight = ${getToken('md.comp.secondary-navigation-tab.active-indicator.height')};
}
''';
}

View File

@@ -8,9 +8,12 @@ import 'token_logger.dart';
/// Base class for code generation templates.
abstract class TokenTemplate {
const TokenTemplate(this.blockName, this.fileName, this._tokens, {
const TokenTemplate(
this.blockName,
this.fileName,
this._tokens, {
this.colorSchemePrefix = 'Theme.of(context).colorScheme.',
this.textThemePrefix = 'Theme.of(context).textTheme.'
this.textThemePrefix = 'Theme.of(context).textTheme.',
});
/// Name of the code block that this template will generate.
@@ -58,6 +61,13 @@ abstract class TokenTemplate {
// Design token database by the script:
// dev/tools/gen_defaults/bin/gen_defaults.dart.
// dart format off
''';
// TODO(goderbauer): Update the script to output auto-formatted code and remove
// "dart format off/on" from headerComment and footerComment.
static const String footerComment = '''
// dart format on
''';
static const String endGeneratedComment = '''
@@ -95,6 +105,7 @@ abstract class TokenTemplate {
buffer.write(beginComment);
buffer.write(headerComment);
buffer.write(generate());
buffer.write(footerComment);
buffer.write(endComment);
buffer.write(contentAfterBlock);
File(fileName).writeAsStringSync(buffer.toString());
@@ -194,8 +205,14 @@ abstract class TokenTemplate {
if (!tokenAvailable(widthToken) && !tokenAvailable(heightToken)) {
throw Exception('Unable to find width, height, or size tokens for $componentToken');
}
final String? width = _numToString(tokenAvailable(widthToken) ? getToken(widthToken)! as num : double.infinity, 0);
final String? height = _numToString(tokenAvailable(heightToken) ? getToken(heightToken)! as num : double.infinity, 0);
final String? width = _numToString(
tokenAvailable(widthToken) ? getToken(widthToken)! as num : double.infinity,
0,
);
final String? height = _numToString(
tokenAvailable(heightToken) ? getToken(heightToken)! as num : double.infinity,
0,
);
return 'const Size($width, $height)';
}
return 'const Size.square(${_numToString(getToken(sizeToken))})';
@@ -207,8 +224,8 @@ abstract class TokenTemplate {
/// - "SHAPE_FAMILY_ROUNDED_CORNERS" which maps to [RoundedRectangleBorder].
/// - "SHAPE_FAMILY_CIRCULAR" which maps to a [StadiumBorder].
String shape(String componentToken, [String prefix = 'const ']) {
final Map<String, dynamic> shape = getToken(getToken('$componentToken.shape') as String) as Map<String, dynamic>;
final Map<String, dynamic> shape =
getToken(getToken('$componentToken.shape') as String) as Map<String, dynamic>;
switch (shape['family']) {
case 'SHAPE_FAMILY_ROUNDED_CORNERS':
final double topLeft = shape['topLeft'] as double;
@@ -223,18 +240,18 @@ abstract class TokenTemplate {
}
if (topLeft == topRight && bottomLeft == bottomRight) {
return '${prefix}RoundedRectangleBorder(borderRadius: BorderRadius.vertical('
'${topLeft > 0 ? 'top: Radius.circular($topLeft)':''}'
'${topLeft > 0 && bottomLeft > 0 ? ',':''}'
'${bottomLeft > 0 ? 'bottom: Radius.circular($bottomLeft)':''}'
'))';
'${topLeft > 0 ? 'top: Radius.circular($topLeft)' : ''}'
'${topLeft > 0 && bottomLeft > 0 ? ',' : ''}'
'${bottomLeft > 0 ? 'bottom: Radius.circular($bottomLeft)' : ''}'
'))';
}
return '${prefix}RoundedRectangleBorder(borderRadius: '
'BorderRadius.only('
'topLeft: Radius.circular(${shape['topLeft']}), '
'topRight: Radius.circular(${shape['topRight']}), '
'bottomLeft: Radius.circular(${shape['bottomLeft']}), '
'bottomRight: Radius.circular(${shape['bottomRight']})))';
case 'SHAPE_FAMILY_CIRCULAR':
'BorderRadius.only('
'topLeft: Radius.circular(${shape['topLeft']}), '
'topRight: Radius.circular(${shape['topRight']}), '
'bottomLeft: Radius.circular(${shape['bottomLeft']}), '
'bottomRight: Radius.circular(${shape['bottomRight']})))';
case 'SHAPE_FAMILY_CIRCULAR':
return '${prefix}StadiumBorder()';
}
print('Unsupported shape family type: ${shape['family']} for $componentToken');
@@ -243,27 +260,24 @@ abstract class TokenTemplate {
/// Generate a [BorderSide] for the given component.
String border(String componentToken) {
if (!tokenAvailable('$componentToken.color')) {
return 'null';
}
final String borderColor = componentColor(componentToken);
final double width = (
getToken('$componentToken.width', optional: true) ??
getToken('$componentToken.height', optional: true) ??
1.0
) as double;
final double width =
(getToken('$componentToken.width', optional: true) ??
getToken('$componentToken.height', optional: true) ??
1.0)
as double;
return 'BorderSide(color: $borderColor${width != 1.0 ? ", width: $width" : ""})';
}
/// Generate a [TextTheme] text style name for the given component token.
String textStyle(String componentToken) {
return '$textThemePrefix${getToken("$componentToken.text-style")}';
}
String textStyleWithColor(String componentToken) {
if (!tokenAvailable('$componentToken.text-style')) {
return 'null';
}

View File

@@ -5,9 +5,12 @@
import 'template.dart';
class TimePickerTemplate extends TokenTemplate {
const TimePickerTemplate(super.blockName, super.fileName, super.tokens, {
const TimePickerTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
super.textThemePrefix = '_textTheme.'
super.textThemePrefix = '_textTheme.',
});
static const String tokenGroup = 'md.comp.time-picker';

View File

@@ -13,8 +13,8 @@ class TokenLogger {
void init({
required Map<String, dynamic> allTokens,
required Map<String, List<String>> versionMap
}){
required Map<String, List<String>> versionMap,
}) {
_allTokens = allTokens;
_versionMap = versionMap;
}
@@ -83,7 +83,11 @@ class TokenLogger {
if (_unavailableTokens.isNotEmpty) {
print('');
print('\x1B[31m' 'Some referenced tokens do not exist: ${_unavailableTokens.length}' '\x1B[0m');
print(
'\x1B[31m'
'Some referenced tokens do not exist: ${_unavailableTokens.length}'
'\x1B[0m',
);
for (final String token in _unavailableTokens) {
print(' $token');
}

View File

@@ -20,21 +20,51 @@ abstract final class _M3Typography {
String _textTheme(String name, String baseline) {
final StringBuffer theme = StringBuffer('static const TextTheme $name = TextTheme(\n');
theme.writeln(' displayLarge: ${_textStyleDef('md.sys.typescale.display-large', '$name displayLarge 2021', baseline)},');
theme.writeln(' displayMedium: ${_textStyleDef('md.sys.typescale.display-medium', '$name displayMedium 2021', baseline)},');
theme.writeln(' displaySmall: ${_textStyleDef('md.sys.typescale.display-small', '$name displaySmall 2021', baseline)},');
theme.writeln(' headlineLarge: ${_textStyleDef('md.sys.typescale.headline-large', '$name headlineLarge 2021', baseline)},');
theme.writeln(' headlineMedium: ${_textStyleDef('md.sys.typescale.headline-medium', '$name headlineMedium 2021', baseline)},');
theme.writeln(' headlineSmall: ${_textStyleDef('md.sys.typescale.headline-small', '$name headlineSmall 2021', baseline)},');
theme.writeln(' titleLarge: ${_textStyleDef('md.sys.typescale.title-large', '$name titleLarge 2021', baseline)},');
theme.writeln(' titleMedium: ${_textStyleDef('md.sys.typescale.title-medium', '$name titleMedium 2021', baseline)},');
theme.writeln(' titleSmall: ${_textStyleDef('md.sys.typescale.title-small', '$name titleSmall 2021', baseline)},');
theme.writeln(' labelLarge: ${_textStyleDef('md.sys.typescale.label-large', '$name labelLarge 2021', baseline)},');
theme.writeln(' labelMedium: ${_textStyleDef('md.sys.typescale.label-medium', '$name labelMedium 2021', baseline)},');
theme.writeln(' labelSmall: ${_textStyleDef('md.sys.typescale.label-small', '$name labelSmall 2021', baseline)},');
theme.writeln(' bodyLarge: ${_textStyleDef('md.sys.typescale.body-large', '$name bodyLarge 2021', baseline)},');
theme.writeln(' bodyMedium: ${_textStyleDef('md.sys.typescale.body-medium', '$name bodyMedium 2021', baseline)},');
theme.writeln(' bodySmall: ${_textStyleDef('md.sys.typescale.body-small', '$name bodySmall 2021', baseline)},');
theme.writeln(
' displayLarge: ${_textStyleDef('md.sys.typescale.display-large', '$name displayLarge 2021', baseline)},',
);
theme.writeln(
' displayMedium: ${_textStyleDef('md.sys.typescale.display-medium', '$name displayMedium 2021', baseline)},',
);
theme.writeln(
' displaySmall: ${_textStyleDef('md.sys.typescale.display-small', '$name displaySmall 2021', baseline)},',
);
theme.writeln(
' headlineLarge: ${_textStyleDef('md.sys.typescale.headline-large', '$name headlineLarge 2021', baseline)},',
);
theme.writeln(
' headlineMedium: ${_textStyleDef('md.sys.typescale.headline-medium', '$name headlineMedium 2021', baseline)},',
);
theme.writeln(
' headlineSmall: ${_textStyleDef('md.sys.typescale.headline-small', '$name headlineSmall 2021', baseline)},',
);
theme.writeln(
' titleLarge: ${_textStyleDef('md.sys.typescale.title-large', '$name titleLarge 2021', baseline)},',
);
theme.writeln(
' titleMedium: ${_textStyleDef('md.sys.typescale.title-medium', '$name titleMedium 2021', baseline)},',
);
theme.writeln(
' titleSmall: ${_textStyleDef('md.sys.typescale.title-small', '$name titleSmall 2021', baseline)},',
);
theme.writeln(
' labelLarge: ${_textStyleDef('md.sys.typescale.label-large', '$name labelLarge 2021', baseline)},',
);
theme.writeln(
' labelMedium: ${_textStyleDef('md.sys.typescale.label-medium', '$name labelMedium 2021', baseline)},',
);
theme.writeln(
' labelSmall: ${_textStyleDef('md.sys.typescale.label-small', '$name labelSmall 2021', baseline)},',
);
theme.writeln(
' bodyLarge: ${_textStyleDef('md.sys.typescale.body-large', '$name bodyLarge 2021', baseline)},',
);
theme.writeln(
' bodyMedium: ${_textStyleDef('md.sys.typescale.body-medium', '$name bodyMedium 2021', baseline)},',
);
theme.writeln(
' bodySmall: ${_textStyleDef('md.sys.typescale.body-small', '$name bodySmall 2021', baseline)},',
);
theme.write(' );');
return theme.toString();
}
@@ -57,7 +87,8 @@ abstract final class _M3Typography {
}
String _fontWeight(String textStyleTokenName) {
final String weightValue = getToken(getToken('$textStyleTokenName.weight') as String).toString();
final String weightValue =
getToken(getToken('$textStyleTokenName.weight') as String).toString();
return 'FontWeight.w$weightValue';
}