From e82e94b28a6e81f9097b6f5f70992019fb5beb7e Mon Sep 17 00:00:00 2001 From: Darren Austin Date: Wed, 2 Feb 2022 16:13:56 -0800 Subject: [PATCH] Updated the defaults to only use function overrides for computed values. (#97677) --- dev/tools/gen_defaults/lib/fab_template.dart | 55 ++++----- .../src/material/floating_action_button.dart | 109 ++++++++---------- 2 files changed, 72 insertions(+), 92 deletions(-) diff --git a/dev/tools/gen_defaults/lib/fab_template.dart b/dev/tools/gen_defaults/lib/fab_template.dart index 0b30c17e37..c7d7add1af 100644 --- a/dev/tools/gen_defaults/lib/fab_template.dart +++ b/dev/tools/gen_defaults/lib/fab_template.dart @@ -13,7 +13,30 @@ class FABTemplate extends TokenTemplate { class _M3Defaults extends FloatingActionButtonThemeData { _M3Defaults(this.context, this.type, this.hasChild) : _colors = Theme.of(context).colorScheme, - _textTheme = Theme.of(context).textTheme; + _textTheme = Theme.of(context).textTheme, + super( + elevation: ${elevation("md.comp.fab.primary.container.elevation")}, + focusElevation: ${elevation("md.comp.fab.primary.focus.container.elevation")}, + hoverElevation: ${elevation("md.comp.fab.primary.hover.container.elevation")}, + highlightElevation: ${elevation("md.comp.fab.primary.pressed.container.elevation")}, + enableFeedback: true, + sizeConstraints: const BoxConstraints.tightFor( + width: ${tokens["md.comp.fab.primary.container.width"]}, + height: ${tokens["md.comp.fab.primary.container.height"]}, + ), + smallSizeConstraints: const BoxConstraints.tightFor( + width: ${tokens["md.comp.fab.primary.small.container.width"]}, + height: ${tokens["md.comp.fab.primary.small.container.height"]}, + ), + largeSizeConstraints: const BoxConstraints.tightFor( + width: ${tokens["md.comp.fab.primary.large.container.width"]}, + height: ${tokens["md.comp.fab.primary.large.container.height"]}, + ), + extendedSizeConstraints: const BoxConstraints.tightFor( + height: ${tokens["md.comp.extended-fab.primary.container.height"]}, + ), + extendedIconLabelSpacing: 8.0, + ); final BuildContext context; final _FloatingActionButtonType type; @@ -26,12 +49,8 @@ class _M3Defaults extends FloatingActionButtonThemeData { @override Color? get foregroundColor => _colors.${color("md.comp.fab.primary.icon")}; @override Color? get backgroundColor => _colors.${color("md.comp.fab.primary.container")}; @override Color? get splashColor => _colors.${color("md.comp.fab.primary.pressed.state-layer")}; - @override double get elevation => ${elevation("md.comp.fab.primary.container.elevation")}; @override Color? get focusColor => _colors.${color("md.comp.fab.primary.focus.state-layer")}; - @override double get focusElevation => ${elevation("md.comp.fab.primary.focus.container.elevation")}; @override Color? get hoverColor => _colors.${color("md.comp.fab.primary.hover.state-layer")}; - @override double get hoverElevation => ${elevation("md.comp.fab.primary.hover.container.elevation")}; - @override double get highlightElevation => ${elevation("md.comp.fab.primary.pressed.container.elevation")}; @override ShapeBorder? get shape { @@ -47,8 +66,6 @@ class _M3Defaults extends FloatingActionButtonThemeData { } } - @override bool? get enableFeedback => true; - @override double? get iconSize { switch (type) { @@ -59,30 +76,6 @@ class _M3Defaults extends FloatingActionButtonThemeData { } } - @override - BoxConstraints? get sizeConstraints => const BoxConstraints.tightFor( - width: ${tokens["md.comp.fab.primary.container.width"]}, - height: ${tokens["md.comp.fab.primary.container.height"]}, - ); - - @override - BoxConstraints? get smallSizeConstraints => const BoxConstraints.tightFor( - width: ${tokens["md.comp.fab.primary.small.container.width"]}, - height: ${tokens["md.comp.fab.primary.small.container.height"]}, - ); - - @override - BoxConstraints? get largeSizeConstraints => const BoxConstraints.tightFor( - width: ${tokens["md.comp.fab.primary.large.container.width"]}, - height: ${tokens["md.comp.fab.primary.large.container.height"]}, - ); - - @override - BoxConstraints? get extendedSizeConstraints => const BoxConstraints.tightFor( - height: ${tokens["md.comp.extended-fab.primary.container.height"]}, - ); - - @override double? get extendedIconLabelSpacing => 8.0; @override EdgeInsetsGeometry? get extendedPadding => EdgeInsetsDirectional.only(start: hasChild && _isExtended ? 16.0 : 20.0, end: 20.0); @override TextStyle? get extendedTextStyle => _textTheme.${textStyle("md.comp.extended-fab.primary.label-text")}; } diff --git a/packages/flutter/lib/src/material/floating_action_button.dart b/packages/flutter/lib/src/material/floating_action_button.dart index a081342015..75c6fd3e22 100644 --- a/packages/flutter/lib/src/material/floating_action_button.dart +++ b/packages/flutter/lib/src/material/floating_action_button.dart @@ -720,7 +720,30 @@ class _RenderChildOverflowBox extends RenderAligningShiftedBox { class _M2Defaults extends FloatingActionButtonThemeData { _M2Defaults(BuildContext context, this.type, this.hasChild) : _theme = Theme.of(context), - _colors = Theme.of(context).colorScheme; + _colors = Theme.of(context).colorScheme, + super( + elevation: 6, + focusElevation: 6, + hoverElevation: 8, + highlightElevation: 12, + 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: 48.0, + ), + extendedIconLabelSpacing: 8.0, + ); final _FloatingActionButtonType type; final bool hasChild; @@ -735,38 +758,9 @@ class _M2Defaults extends FloatingActionButtonThemeData { @override Color? get focusColor => _theme.focusColor; @override Color? get hoverColor => _theme.hoverColor; @override Color? get splashColor => _theme.splashColor; - @override double? get elevation => 6; - @override double? get focusElevation => 6; - @override double? get hoverElevation => 8; - @override double? get highlightElevation => 12; @override ShapeBorder? get shape => _isExtended ? const StadiumBorder() : const CircleBorder(); - @override bool? get enableFeedback => true; @override double? get iconSize => _isLarge ? 36.0 : 24.0; - @override - BoxConstraints? get sizeConstraints => const BoxConstraints.tightFor( - width: 56.0, - height: 56.0, - ); - - @override - BoxConstraints? get smallSizeConstraints => const BoxConstraints.tightFor( - width: 40.0, - height: 40.0, - ); - - @override - BoxConstraints? get largeSizeConstraints => const BoxConstraints.tightFor( - width: 96.0, - height: 96.0, - ); - - @override - BoxConstraints? get extendedSizeConstraints => const BoxConstraints.tightFor( - height: 48.0, - ); - - @override double? get extendedIconLabelSpacing => 8.0; @override EdgeInsetsGeometry? get extendedPadding => EdgeInsetsDirectional.only(start: hasChild && _isExtended ? 16.0 : 20.0, end: 20.0); @override TextStyle? get extendedTextStyle => _theme.textTheme.button!.copyWith(letterSpacing: 1.2); } @@ -781,7 +775,30 @@ class _M2Defaults extends FloatingActionButtonThemeData { class _M3Defaults extends FloatingActionButtonThemeData { _M3Defaults(this.context, this.type, this.hasChild) : _colors = Theme.of(context).colorScheme, - _textTheme = Theme.of(context).textTheme; + _textTheme = Theme.of(context).textTheme, + 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; @@ -794,12 +811,8 @@ class _M3Defaults extends FloatingActionButtonThemeData { @override Color? get foregroundColor => _colors.onPrimaryContainer; @override Color? get backgroundColor => _colors.primaryContainer; @override Color? get splashColor => _colors.onPrimaryContainer.withOpacity(0.12); - @override double get elevation => 6.0; @override Color? get focusColor => _colors.onPrimaryContainer.withOpacity(0.12); - @override double get focusElevation => 6.0; @override Color? get hoverColor => _colors.onPrimaryContainer.withOpacity(0.08); - @override double get hoverElevation => 8.0; - @override double get highlightElevation => 6.0; @override ShapeBorder? get shape { @@ -815,8 +828,6 @@ class _M3Defaults extends FloatingActionButtonThemeData { } } - @override bool? get enableFeedback => true; - @override double? get iconSize { switch (type) { @@ -827,30 +838,6 @@ class _M3Defaults extends FloatingActionButtonThemeData { } } - @override - BoxConstraints? get sizeConstraints => const BoxConstraints.tightFor( - width: 56.0, - height: 56.0, - ); - - @override - BoxConstraints? get smallSizeConstraints => const BoxConstraints.tightFor( - width: 40.0, - height: 40.0, - ); - - @override - BoxConstraints? get largeSizeConstraints => const BoxConstraints.tightFor( - width: 96.0, - height: 96.0, - ); - - @override - BoxConstraints? get extendedSizeConstraints => const BoxConstraints.tightFor( - height: 56.0, - ); - - @override double? get extendedIconLabelSpacing => 8.0; @override EdgeInsetsGeometry? get extendedPadding => EdgeInsetsDirectional.only(start: hasChild && _isExtended ? 16.0 : 20.0, end: 20.0); @override TextStyle? get extendedTextStyle => _textTheme.labelLarge; }