diff --git a/packages/material_ui/lib/src/floating_action_button.dart b/packages/material_ui/lib/src/floating_action_button.dart index 3989b3dcf979..2a0a8ea0e7ae 100644 --- a/packages/material_ui/lib/src/floating_action_button.dart +++ b/packages/material_ui/lib/src/floating_action_button.dart @@ -21,6 +21,8 @@ import 'text_theme.dart'; import 'theme.dart'; import 'tooltip.dart'; +part 'generated/fab_defaults_m3.g.dart'; + class _DefaultHeroTag { const _DefaultHeroTag(); @override @@ -781,74 +783,3 @@ class _FABDefaultsM2 extends FloatingActionButtonThemeData { @override TextStyle? get extendedTextStyle => _theme.textTheme.labelLarge!.copyWith(letterSpacing: 1.2); } - -// BEGIN GENERATED TOKEN PROPERTIES - FAB - -// Do not edit by hand. The code between the "BEGIN GENERATED" and -// "END GENERATED" comments are generated from data in the Material -// Design token database by the script: -// dev/tools/gen_defaults/bin/gen_defaults.dart. - -// dart format off -class _FABDefaultsM3 extends FloatingActionButtonThemeData { - _FABDefaultsM3(this.context, this.type, this.hasChild) - : super( - elevation: 6.0, - focusElevation: 6.0, - hoverElevation: 8.0, - highlightElevation: 6.0, - enableFeedback: true, - sizeConstraints: const BoxConstraints.tightFor( - width: 56.0, - height: 56.0, - ), - smallSizeConstraints: const BoxConstraints.tightFor( - width: 40.0, - height: 40.0, - ), - largeSizeConstraints: const BoxConstraints.tightFor( - width: 96.0, - height: 96.0, - ), - extendedSizeConstraints: const BoxConstraints.tightFor( - height: 56.0, - ), - extendedIconLabelSpacing: 8.0, - ); - - final BuildContext context; - final _FloatingActionButtonType type; - final bool hasChild; - late final ColorScheme _colors = Theme.of(context).colorScheme; - late final TextTheme _textTheme = Theme.of(context).textTheme; - - bool get _isExtended => type == _FloatingActionButtonType.extended; - - @override Color? get foregroundColor => _colors.onPrimaryContainer; - @override Color? get backgroundColor => _colors.primaryContainer; - @override Color? get splashColor => _colors.onPrimaryContainer.withOpacity(0.1); - @override Color? get focusColor => _colors.onPrimaryContainer.withOpacity(0.1); - @override Color? get hoverColor => _colors.onPrimaryContainer.withOpacity(0.08); - - @override - ShapeBorder? get shape => switch (type) { - _FloatingActionButtonType.regular => const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16.0))), - _FloatingActionButtonType.small => const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(12.0))), - _FloatingActionButtonType.large => const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(28.0))), - _FloatingActionButtonType.extended => const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16.0))), - }; - - @override - double? get iconSize => switch (type) { - _FloatingActionButtonType.regular => 24.0, - _FloatingActionButtonType.small => 24.0, - _FloatingActionButtonType.large => 36.0, - _FloatingActionButtonType.extended => 24.0, - }; - - @override EdgeInsetsGeometry? get extendedPadding => EdgeInsetsDirectional.only(start: hasChild && _isExtended ? 16.0 : 20.0, end: 20.0); - @override TextStyle? get extendedTextStyle => _textTheme.labelLarge; -} -// dart format on - -// END GENERATED TOKEN PROPERTIES - FAB diff --git a/packages/material_ui/tool/gen_defaults/temporarily_excluded/generated/fab_defaults.g.dart b/packages/material_ui/lib/src/generated/fab_defaults_m3.g.dart similarity index 92% rename from packages/material_ui/tool/gen_defaults/temporarily_excluded/generated/fab_defaults.g.dart rename to packages/material_ui/lib/src/generated/fab_defaults_m3.g.dart index 0693fb156534..0482c12dfea6 100644 --- a/packages/material_ui/tool/gen_defaults/temporarily_excluded/generated/fab_defaults.g.dart +++ b/packages/material_ui/lib/src/generated/fab_defaults_m3.g.dart @@ -2,6 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// Do not edit by hand. The code is generated from data in the Material +// Design token database by the script: +// packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart. +part of '../floating_action_button.dart'; + class _FABDefaultsM3 extends FloatingActionButtonThemeData { _FABDefaultsM3(this.context, this.type, this.hasChild) : super( diff --git a/packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart b/packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart index 849621e5b575..e91189619c70 100644 --- a/packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart +++ b/packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart @@ -29,7 +29,7 @@ import '../templates/card_template.dart'; // import '../templates/divider_template.dart'; // import '../templates/drawer_template.dart'; // import '../templates/expansion_tile_template.dart'; -// import '../templates/fab_template.dart'; +import '../templates/fab_template.dart'; // import '../templates/filter_chip_template.dart'; // import '../templates/icon_button_template.dart'; // import '../templates/input_chip_template.dart'; @@ -86,7 +86,7 @@ Future main(List args) async { // const DividerTemplateM3().generateFile(verbose: verbose); // const DrawerTemplateM3().generateFile(verbose: verbose); // const ExpansionTileTemplateM3().generateFile(verbose: verbose); - // const FabTemplateM3().generateFile(verbose: verbose); + const FabTemplateM3().generateFile(verbose: verbose); // const FilterChipTemplateM3().generateFile(verbose: verbose); // const IconButtonTemplateM3().generateFile(verbose: verbose); // const InputChipTemplateM3().generateFile(verbose: verbose); diff --git a/packages/material_ui/tool/gen_defaults/templates/fab_template.dart b/packages/material_ui/tool/gen_defaults/templates/fab_template.dart new file mode 100644 index 000000000000..0df4bd0c7593 --- /dev/null +++ b/packages/material_ui/tool/gen_defaults/templates/fab_template.dart @@ -0,0 +1,87 @@ +// Copyright 2013 The Flutter Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import '../data/extended_fab.dart'; +import '../data/fab.dart'; +import '../data/fab_large.dart'; +import '../data/fab_primary_container.dart'; +import '../data/fab_small.dart'; +import 'template.dart'; + +class FabTemplateM3 extends TokenTemplateM3 { + const FabTemplateM3(); + + @override + String get name => 'FAB'; + + @override + String get parentFilePath => 'floating_action_button.dart'; + + @override + String get className => '_FABDefaultsM3'; + + @override + String generateContents(String className) => + ''' +class $className extends FloatingActionButtonThemeData { + $className(this.context, this.type, this.hasChild) + : super( + elevation: ${number(TokenFabPrimaryContainer.containerElevation)}, + focusElevation: ${number(TokenFabPrimaryContainer.focusedContainerElevation)}, + hoverElevation: ${number(TokenFabPrimaryContainer.hoveredContainerElevation)}, + highlightElevation: ${number(TokenFabPrimaryContainer.pressedContainerElevation)}, + enableFeedback: true, + sizeConstraints: const BoxConstraints.tightFor( + width: ${number(TokenFab.containerWidth)}, + height: ${number(TokenFab.containerHeight)}, + ), + smallSizeConstraints: const BoxConstraints.tightFor( + width: ${number(TokenFabSmall.containerWidth)}, + height: ${number(TokenFabSmall.containerHeight)}, + ), + largeSizeConstraints: const BoxConstraints.tightFor( + width: ${number(TokenFabLarge.containerWidth)}, + height: ${number(TokenFabLarge.containerHeight)}, + ), + extendedSizeConstraints: const BoxConstraints.tightFor( + height: ${number(TokenExtendedFab.containerHeight)}, + ), + extendedIconLabelSpacing: 8.0, + ); + + final BuildContext context; + final _FloatingActionButtonType type; + final bool hasChild; + late final ColorScheme _colors = Theme.of(context).colorScheme; + late final TextTheme _textTheme = Theme.of(context).textTheme; + + bool get _isExtended => type == _FloatingActionButtonType.extended; + + @override Color? get foregroundColor => ${color(TokenFabPrimaryContainer.iconColor)}; + @override Color? get backgroundColor => ${color(TokenFabPrimaryContainer.containerColor)}; + @override Color? get splashColor => ${colorWithOpacity(TokenFabPrimaryContainer.pressedStateLayerColor, TokenFabPrimaryContainer.pressedStateLayerOpacity)}; + @override Color? get focusColor => ${colorWithOpacity(TokenFabPrimaryContainer.focusedStateLayerColor, TokenFabPrimaryContainer.focusedStateLayerOpacity)}; + @override Color? get hoverColor => ${colorWithOpacity(TokenFabPrimaryContainer.hoveredStateLayerColor, TokenFabPrimaryContainer.hoveredStateLayerOpacity)}; + + @override + ShapeBorder? get shape => switch (type) { + _FloatingActionButtonType.regular => ${shape(TokenFab.containerShape)}, + _FloatingActionButtonType.small => ${shape(TokenFabSmall.containerShape)}, + _FloatingActionButtonType.large => ${shape(TokenFabLarge.containerShape)}, + _FloatingActionButtonType.extended => ${shape(TokenExtendedFab.containerShape)}, + }; + + @override + double? get iconSize => switch (type) { + _FloatingActionButtonType.regular => ${number(TokenFab.iconSize)}, + _FloatingActionButtonType.small => ${number(TokenFabSmall.iconSize)}, + _FloatingActionButtonType.large => ${number(TokenFabLarge.iconSize)}, + _FloatingActionButtonType.extended => ${number(TokenExtendedFab.iconSize)}, + }; + + @override EdgeInsetsGeometry? get extendedPadding => EdgeInsetsDirectional.only(start: hasChild && _isExtended ? ${number(TokenExtendedFab.leadingSpace)} : ${number(TokenExtendedFab.trailingSpace)}, end: ${number(TokenExtendedFab.trailingSpace)}); + @override TextStyle? get extendedTextStyle => ${textStyle(TokenExtendedFab.labelText, '_textTheme')}; +} +'''; +} diff --git a/packages/material_ui/tool/gen_defaults/temporarily_excluded/templates/fab_template.dart b/packages/material_ui/tool/gen_defaults/temporarily_excluded/templates/fab_template.dart deleted file mode 100644 index ef6d5e674587..000000000000 --- a/packages/material_ui/tool/gen_defaults/temporarily_excluded/templates/fab_template.dart +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2013 The Flutter Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'template.dart'; - -class FABTemplate extends TokenTemplate { - const FABTemplate( - super.blockName, - super.fileName, - super.tokens, { - super.colorSchemePrefix = '_colors.', - super.textThemePrefix = '_textTheme.', - }); - - @override - String generate() => - ''' -class _${blockName}DefaultsM3 extends FloatingActionButtonThemeData { - _${blockName}DefaultsM3(this.context, this.type, this.hasChild) - : super( - elevation: ${elevation("md.comp.fab.primary.container")}, - focusElevation: ${elevation("md.comp.fab.primary.focus.container")}, - hoverElevation: ${elevation("md.comp.fab.primary.hover.container")}, - highlightElevation: ${elevation("md.comp.fab.primary.pressed.container")}, - enableFeedback: true, - sizeConstraints: const BoxConstraints.tightFor( - width: ${getToken("md.comp.fab.primary.container.width")}, - height: ${getToken("md.comp.fab.primary.container.height")}, - ), - smallSizeConstraints: const BoxConstraints.tightFor( - width: ${getToken("md.comp.fab.primary.small.container.width")}, - height: ${getToken("md.comp.fab.primary.small.container.height")}, - ), - largeSizeConstraints: const BoxConstraints.tightFor( - width: ${getToken("md.comp.fab.primary.large.container.width")}, - height: ${getToken("md.comp.fab.primary.large.container.height")}, - ), - extendedSizeConstraints: const BoxConstraints.tightFor( - height: ${getToken("md.comp.extended-fab.primary.container.height")}, - ), - extendedIconLabelSpacing: 8.0, - ); - - final BuildContext context; - final _FloatingActionButtonType type; - final bool hasChild; - late final ColorScheme _colors = Theme.of(context).colorScheme; - late final TextTheme _textTheme = Theme.of(context).textTheme; - - bool get _isExtended => type == _FloatingActionButtonType.extended; - - @override Color? get foregroundColor => ${componentColor("md.comp.fab.primary.icon")}; - @override Color? get backgroundColor => ${componentColor("md.comp.fab.primary.container")}; - @override Color? get splashColor => ${componentColor("md.comp.fab.primary.pressed.state-layer")}; - @override Color? get focusColor => ${componentColor("md.comp.fab.primary.focus.state-layer")}; - @override Color? get hoverColor => ${componentColor("md.comp.fab.primary.hover.state-layer")}; - - @override - ShapeBorder? get shape => switch (type) { - _FloatingActionButtonType.regular => ${shape("md.comp.fab.primary.container")}, - _FloatingActionButtonType.small => ${shape("md.comp.fab.primary.small.container")}, - _FloatingActionButtonType.large => ${shape("md.comp.fab.primary.large.container")}, - _FloatingActionButtonType.extended => ${shape("md.comp.extended-fab.primary.container")}, - }; - - @override - double? get iconSize => switch (type) { - _FloatingActionButtonType.regular => ${getToken("md.comp.fab.primary.icon.size")}, - _FloatingActionButtonType.small => ${getToken("md.comp.fab.primary.small.icon.size")}, - _FloatingActionButtonType.large => ${getToken("md.comp.fab.primary.large.icon.size")}, - _FloatingActionButtonType.extended => ${getToken("md.comp.extended-fab.primary.icon.size")}, - }; - - @override EdgeInsetsGeometry? get extendedPadding => EdgeInsetsDirectional.only(start: hasChild && _isExtended ? 16.0 : 20.0, end: 20.0); - @override TextStyle? get extendedTextStyle => ${textStyle("md.comp.extended-fab.primary.label-text")}; -} -'''; -} diff --git a/packages/material_ui/tool/gen_defaults/test/gen_defaults_test.dart b/packages/material_ui/tool/gen_defaults/test/gen_defaults_test.dart index f9185c0b5ef8..703a0a80635a 100644 --- a/packages/material_ui/tool/gen_defaults/test/gen_defaults_test.dart +++ b/packages/material_ui/tool/gen_defaults/test/gen_defaults_test.dart @@ -25,7 +25,7 @@ import '../templates/card_template.dart'; // import '../templates/divider_template.dart'; // import '../templates/drawer_template.dart'; // import '../templates/expansion_tile_template.dart'; -// import '../templates/fab_template.dart'; +import '../templates/fab_template.dart'; // import '../templates/filter_chip_template.dart'; // import '../templates/icon_button_template.dart'; // import '../templates/input_chip_template.dart'; @@ -509,8 +509,13 @@ void main() { }); test('FabTemplateM3 emits M3 Fab defaults from tokens', () { - // Intentionally empty, will be implemented during migration. See: - // https://github.com/flutter/flutter/issues/187899 + const template = FabTemplateM3(); + expect(template.className, '_FABDefaultsM3'); + + final String contents = _generateContents(template); + expect(contents, contains('Color? get backgroundColor => _colors.primaryContainer')); + expect(contents, contains(RegExp(r'_FloatingActionButtonType\.large\s+=> 36\.0'))); + expect(contents, contains('TextStyle? get extendedTextStyle => _textTheme.labelLarge')); }); test('FilterChipTemplateM3 emits M3 FilterChip defaults from tokens', () {