From 31719941c080779ca2bcffb681592b14838aefc9 Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Tue, 6 Dec 2022 18:07:25 -0800 Subject: [PATCH] Time picker precursors (#116450) * Make some minor changes in preparation for updating the Time Picker to M3 * Revert OutlineInputBorder.borderRadius type change * Revert more OutlineInputBorder.borderRadius changes. --- .../lib/input_decorator_template.dart | 8 ++-- .../gen_defaults/lib/snackbar_template.dart | 6 +-- dev/tools/gen_defaults/lib/template.dart | 32 +++++++++++++--- .../lib/src/material/input_decorator.dart | 8 ++-- .../lib/src/material/material_state.dart | 1 - .../flutter/lib/src/material/menu_anchor.dart | 37 ++++++++++--------- .../flutter/lib/src/material/snack_bar.dart | 6 +-- .../flutter/lib/src/material/text_field.dart | 2 +- .../test/painting/system_fonts_test.dart | 4 +- 9 files changed, 60 insertions(+), 44 deletions(-) diff --git a/dev/tools/gen_defaults/lib/input_decorator_template.dart b/dev/tools/gen_defaults/lib/input_decorator_template.dart index fa0d68f5c55..50ba7b42425 100644 --- a/dev/tools/gen_defaults/lib/input_decorator_template.dart +++ b/dev/tools/gen_defaults/lib/input_decorator_template.dart @@ -134,7 +134,7 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme { @override TextStyle? get labelStyle => MaterialStateTextStyle.resolveWith((Set states) { - final TextStyle textStyle= ${textStyle("md.comp.filled-text-field.label-text")} ?? const TextStyle(); + final TextStyle textStyle = ${textStyle("md.comp.filled-text-field.label-text")} ?? const TextStyle(); if(states.contains(MaterialState.error)) { if (states.contains(MaterialState.focused)) { return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.error.focus.label-text')}); @@ -158,7 +158,7 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme { @override TextStyle? get floatingLabelStyle => MaterialStateTextStyle.resolveWith((Set states) { - final TextStyle textStyle= ${textStyle("md.comp.filled-text-field.label-text")} ?? const TextStyle(); + final TextStyle textStyle = ${textStyle("md.comp.filled-text-field.label-text")} ?? const TextStyle(); if(states.contains(MaterialState.error)) { if (states.contains(MaterialState.focused)) { return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.error.focus.label-text')}); @@ -182,7 +182,7 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme { @override TextStyle? get helperStyle => MaterialStateTextStyle.resolveWith((Set states) { - final TextStyle textStyle= ${textStyle("md.comp.filled-text-field.supporting-text")} ?? const TextStyle();${componentColor('md.comp.filled-text-field.focus.supporting-text') == componentColor('md.comp.filled-text-field.supporting-text') ? '' : ''' + final TextStyle textStyle = ${textStyle("md.comp.filled-text-field.supporting-text")} ?? const TextStyle();${componentColor('md.comp.filled-text-field.focus.supporting-text') == componentColor('md.comp.filled-text-field.supporting-text') ? '' : ''' if (states.contains(MaterialState.focused)) { return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.focus.supporting-text')}); }'''}${componentColor('md.comp.filled-text-field.hover.supporting-text') == componentColor('md.comp.filled-text-field.supporting-text') ? '' : ''' @@ -197,7 +197,7 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme { @override TextStyle? get errorStyle => MaterialStateTextStyle.resolveWith((Set states) { - final TextStyle textStyle= ${textStyle("md.comp.filled-text-field.supporting-text")} ?? const TextStyle();${componentColor('md.comp.filled-text-field.error.focus.supporting-text') == componentColor('md.comp.filled-text-field.error.supporting-text') ? '' : ''' + final TextStyle textStyle = ${textStyle("md.comp.filled-text-field.supporting-text")} ?? const TextStyle();${componentColor('md.comp.filled-text-field.error.focus.supporting-text') == componentColor('md.comp.filled-text-field.error.supporting-text') ? '' : ''' if (states.contains(MaterialState.focused)) { return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.error.focus.supporting-text')}); }'''}${componentColor('md.comp.filled-text-field.error.hover.supporting-text') == componentColor('md.comp.filled-text-field.error.supporting-text') ? '' : ''' diff --git a/dev/tools/gen_defaults/lib/snackbar_template.dart b/dev/tools/gen_defaults/lib/snackbar_template.dart index 47aad664cf0..c26f5580ee6 100644 --- a/dev/tools/gen_defaults/lib/snackbar_template.dart +++ b/dev/tools/gen_defaults/lib/snackbar_template.dart @@ -67,10 +67,6 @@ class _${blockName}DefaultsM3 extends SnackBarThemeData { @override bool get showCloseIcon => false; - - @override - Color get iconColor => _colors.onInverseSurface; - } - +} '''; } diff --git a/dev/tools/gen_defaults/lib/template.dart b/dev/tools/gen_defaults/lib/template.dart index f9c11ee983d..b80353f102a 100644 --- a/dev/tools/gen_defaults/lib/template.dart +++ b/dev/tools/gen_defaults/lib/template.dart @@ -26,7 +26,7 @@ abstract class TokenTemplate { /// Defaults to 'Theme.of(context).colorScheme.' final String colorSchemePrefix; - /// Optional prefix prepended to text style definitians. + /// Optional prefix prepended to text style definitions. /// /// Defaults to 'Theme.of(context).textTheme.' final String textThemePrefix; @@ -145,13 +145,17 @@ abstract class TokenTemplate { } /// Generate the opacity value for the given token. - String? opacity(String token) { - final dynamic value = tokens[token]; + String? opacity(String token) => _numToString(tokens[token]); + + String? _numToString(Object? value, [int? digits]) { if (value == null) { return null; } - if (value is double) { - return value.toString(); + if (value is num) { + if (value == double.infinity) { + return 'double.infinity'; + } + return digits == null ? value.toString() : value.toStringAsFixed(digits); } return tokens[value].toString(); } @@ -161,6 +165,24 @@ abstract class TokenTemplate { return tokens[tokens['$componentToken.elevation']!]!.toString(); } + /// Generate a size value for the given component token. + /// + /// Non-square sizes are specified as width and height. + String size(String componentToken) { + final String sizeToken = '$componentToken.size'; + if (!tokens.containsKey(sizeToken)) { + final String widthToken = '$componentToken.width'; + final String heightToken = '$componentToken.height'; + if (!tokens.containsKey(widthToken) && !tokens.containsKey(heightToken)) { + throw Exception('Unable to find width, height, or size tokens for $componentToken'); + } + final String? width = _numToString(tokens.containsKey(widthToken) ? tokens[widthToken]! as num : double.infinity, 0); + final String? height = _numToString(tokens.containsKey(heightToken) ? tokens[heightToken]! as num : double.infinity, 0); + return 'const Size($width, $height)'; + } + return 'const Size.square(${_numToString(tokens[sizeToken])})'; + } + /// Generate a shape constant for the given component token. /// /// Currently supports family: diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index c01e75be92d..193c3b1f0e2 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -4580,7 +4580,7 @@ class _InputDecoratorDefaultsM3 extends InputDecorationTheme { @override TextStyle? get labelStyle => MaterialStateTextStyle.resolveWith((Set states) { - final TextStyle textStyle= _textTheme.bodyLarge ?? const TextStyle(); + final TextStyle textStyle = _textTheme.bodyLarge ?? const TextStyle(); if(states.contains(MaterialState.error)) { if (states.contains(MaterialState.focused)) { return textStyle.copyWith(color:_colors.error); @@ -4604,7 +4604,7 @@ class _InputDecoratorDefaultsM3 extends InputDecorationTheme { @override TextStyle? get floatingLabelStyle => MaterialStateTextStyle.resolveWith((Set states) { - final TextStyle textStyle= _textTheme.bodyLarge ?? const TextStyle(); + final TextStyle textStyle = _textTheme.bodyLarge ?? const TextStyle(); if(states.contains(MaterialState.error)) { if (states.contains(MaterialState.focused)) { return textStyle.copyWith(color:_colors.error); @@ -4628,7 +4628,7 @@ class _InputDecoratorDefaultsM3 extends InputDecorationTheme { @override TextStyle? get helperStyle => MaterialStateTextStyle.resolveWith((Set states) { - final TextStyle textStyle= _textTheme.bodySmall ?? const TextStyle(); + final TextStyle textStyle = _textTheme.bodySmall ?? const TextStyle(); if (states.contains(MaterialState.disabled)) { return textStyle.copyWith(color:_colors.onSurface.withOpacity(0.38)); } @@ -4637,7 +4637,7 @@ class _InputDecoratorDefaultsM3 extends InputDecorationTheme { @override TextStyle? get errorStyle => MaterialStateTextStyle.resolveWith((Set states) { - final TextStyle textStyle= _textTheme.bodySmall ?? const TextStyle(); + final TextStyle textStyle = _textTheme.bodySmall ?? const TextStyle(); return textStyle.copyWith(color:_colors.error); }); } diff --git a/packages/flutter/lib/src/material/material_state.dart b/packages/flutter/lib/src/material/material_state.dart index 12a1dea295e..dd6a9a136a0 100644 --- a/packages/flutter/lib/src/material/material_state.dart +++ b/packages/flutter/lib/src/material/material_state.dart @@ -409,7 +409,6 @@ abstract class MaterialStateOutlinedBorder extends OutlinedBorder implements Mat OutlinedBorder? resolve(Set states); } - /// Defines a [TextStyle] that is also a [MaterialStateProperty]. /// /// This class exists to enable widgets with [TextStyle] valued properties diff --git a/packages/flutter/lib/src/material/menu_anchor.dart b/packages/flutter/lib/src/material/menu_anchor.dart index d0980ecb20f..8d6958c84aa 100644 --- a/packages/flutter/lib/src/material/menu_anchor.dart +++ b/packages/flutter/lib/src/material/menu_anchor.dart @@ -3567,13 +3567,14 @@ bool _platformSupportsAccelerators() { class _MenuBarDefaultsM3 extends MenuStyle { _MenuBarDefaultsM3(this.context) - : super( - elevation: const MaterialStatePropertyAll(3.0), - shape: const MaterialStatePropertyAll(_defaultMenuBorder), - alignment: AlignmentDirectional.bottomStart, - ); + : super( + elevation: const MaterialStatePropertyAll(3.0), + shape: const MaterialStatePropertyAll(_defaultMenuBorder), + alignment: AlignmentDirectional.bottomStart, + ); + static const RoundedRectangleBorder _defaultMenuBorder = - RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0))); + RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0))); final BuildContext context; @@ -3609,11 +3610,12 @@ class _MenuBarDefaultsM3 extends MenuStyle { class _MenuButtonDefaultsM3 extends ButtonStyle { _MenuButtonDefaultsM3(this.context) - : super( - animationDuration: kThemeChangeDuration, - enableFeedback: true, - alignment: AlignmentDirectional.centerStart, - ); + : super( + animationDuration: kThemeChangeDuration, + enableFeedback: true, + alignment: AlignmentDirectional.centerStart, + ); + final BuildContext context; late final ColorScheme _colors = Theme.of(context).colorScheme; @@ -3751,13 +3753,14 @@ class _MenuButtonDefaultsM3 extends ButtonStyle { class _MenuDefaultsM3 extends MenuStyle { _MenuDefaultsM3(this.context) - : super( - elevation: const MaterialStatePropertyAll(3.0), - shape: const MaterialStatePropertyAll(_defaultMenuBorder), - alignment: AlignmentDirectional.topEnd, - ); + : super( + elevation: const MaterialStatePropertyAll(3.0), + shape: const MaterialStatePropertyAll(_defaultMenuBorder), + alignment: AlignmentDirectional.topEnd, + ); + static const RoundedRectangleBorder _defaultMenuBorder = - RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0))); + RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0))); final BuildContext context; diff --git a/packages/flutter/lib/src/material/snack_bar.dart b/packages/flutter/lib/src/material/snack_bar.dart index 85f88238e7e..6dfea7e2dac 100644 --- a/packages/flutter/lib/src/material/snack_bar.dart +++ b/packages/flutter/lib/src/material/snack_bar.dart @@ -883,10 +883,6 @@ class _SnackbarDefaultsM3 extends SnackBarThemeData { @override bool get showCloseIcon => false; - - @override - Color get closeIconColor => _colors.onInverseSurface; - } - +} // END GENERATED TOKEN PROPERTIES - Snackbar diff --git a/packages/flutter/lib/src/material/text_field.dart b/packages/flutter/lib/src/material/text_field.dart index 8ecc70acc51..c72828c92a2 100644 --- a/packages/flutter/lib/src/material/text_field.dart +++ b/packages/flutter/lib/src/material/text_field.dart @@ -1429,6 +1429,6 @@ TextStyle _m2CounterErrorStyle(BuildContext context) => TextStyle _m3InputStyle(BuildContext context) => Theme.of(context).textTheme.bodyLarge!; TextStyle _m3CounterErrorStyle(BuildContext context) => - Theme.of(context).textTheme.bodySmall!.copyWith(color:Theme.of(context).colorScheme.error); + Theme.of(context).textTheme.bodySmall!.copyWith(color: Theme.of(context).colorScheme.error); // END GENERATED TOKEN PROPERTIES - TextField diff --git a/packages/flutter/test/painting/system_fonts_test.dart b/packages/flutter/test/painting/system_fonts_test.dart index 567f658dbbb..c0c1f6111d0 100644 --- a/packages/flutter/test/painting/system_fonts_test.dart +++ b/packages/flutter/test/painting/system_fonts_test.dart @@ -283,8 +283,8 @@ void main() { final RenderObject renderObject = tester.renderObject( find.descendant( of: find.byKey(const Key('parent')), - matching: find.byType(CustomPaint), - ).first, + matching: find.byKey(const ValueKey('time-picker-dial')), + ), ); expect(renderObject.debugNeedsPaint, isTrue); });