Skip to content

Commit 3171994

Browse files
authored
Time picker precursors (flutter#116450)
* Make some minor changes in preparation for updating the Time Picker to M3 * Revert OutlineInputBorder.borderRadius type change * Revert more OutlineInputBorder.borderRadius changes.
1 parent fb9133b commit 3171994

File tree

9 files changed

+60
-44
lines changed

9 files changed

+60
-44
lines changed

dev/tools/gen_defaults/lib/input_decorator_template.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme {
134134
135135
@override
136136
TextStyle? get labelStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) {
137-
final TextStyle textStyle= ${textStyle("md.comp.filled-text-field.label-text")} ?? const TextStyle();
137+
final TextStyle textStyle = ${textStyle("md.comp.filled-text-field.label-text")} ?? const TextStyle();
138138
if(states.contains(MaterialState.error)) {
139139
if (states.contains(MaterialState.focused)) {
140140
return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.error.focus.label-text')});
@@ -158,7 +158,7 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme {
158158
159159
@override
160160
TextStyle? get floatingLabelStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) {
161-
final TextStyle textStyle= ${textStyle("md.comp.filled-text-field.label-text")} ?? const TextStyle();
161+
final TextStyle textStyle = ${textStyle("md.comp.filled-text-field.label-text")} ?? const TextStyle();
162162
if(states.contains(MaterialState.error)) {
163163
if (states.contains(MaterialState.focused)) {
164164
return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.error.focus.label-text')});
@@ -182,7 +182,7 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme {
182182
183183
@override
184184
TextStyle? get helperStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) {
185-
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') ? '' : '''
185+
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') ? '' : '''
186186
if (states.contains(MaterialState.focused)) {
187187
return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.focus.supporting-text')});
188188
}'''}${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 {
197197
198198
@override
199199
TextStyle? get errorStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) {
200-
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') ? '' : '''
200+
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') ? '' : '''
201201
if (states.contains(MaterialState.focused)) {
202202
return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.error.focus.supporting-text')});
203203
}'''}${componentColor('md.comp.filled-text-field.error.hover.supporting-text') == componentColor('md.comp.filled-text-field.error.supporting-text') ? '' : '''

dev/tools/gen_defaults/lib/snackbar_template.dart

+1-5
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ class _${blockName}DefaultsM3 extends SnackBarThemeData {
6767
6868
@override
6969
bool get showCloseIcon => false;
70-
71-
@override
72-
Color get iconColor => _colors.onInverseSurface;
73-
}
74-
70+
}
7571
''';
7672
}

dev/tools/gen_defaults/lib/template.dart

+27-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ abstract class TokenTemplate {
2626
/// Defaults to 'Theme.of(context).colorScheme.'
2727
final String colorSchemePrefix;
2828

29-
/// Optional prefix prepended to text style definitians.
29+
/// Optional prefix prepended to text style definitions.
3030
///
3131
/// Defaults to 'Theme.of(context).textTheme.'
3232
final String textThemePrefix;
@@ -145,13 +145,17 @@ abstract class TokenTemplate {
145145
}
146146

147147
/// Generate the opacity value for the given token.
148-
String? opacity(String token) {
149-
final dynamic value = tokens[token];
148+
String? opacity(String token) => _numToString(tokens[token]);
149+
150+
String? _numToString(Object? value, [int? digits]) {
150151
if (value == null) {
151152
return null;
152153
}
153-
if (value is double) {
154-
return value.toString();
154+
if (value is num) {
155+
if (value == double.infinity) {
156+
return 'double.infinity';
157+
}
158+
return digits == null ? value.toString() : value.toStringAsFixed(digits);
155159
}
156160
return tokens[value].toString();
157161
}
@@ -161,6 +165,24 @@ abstract class TokenTemplate {
161165
return tokens[tokens['$componentToken.elevation']!]!.toString();
162166
}
163167

168+
/// Generate a size value for the given component token.
169+
///
170+
/// Non-square sizes are specified as width and height.
171+
String size(String componentToken) {
172+
final String sizeToken = '$componentToken.size';
173+
if (!tokens.containsKey(sizeToken)) {
174+
final String widthToken = '$componentToken.width';
175+
final String heightToken = '$componentToken.height';
176+
if (!tokens.containsKey(widthToken) && !tokens.containsKey(heightToken)) {
177+
throw Exception('Unable to find width, height, or size tokens for $componentToken');
178+
}
179+
final String? width = _numToString(tokens.containsKey(widthToken) ? tokens[widthToken]! as num : double.infinity, 0);
180+
final String? height = _numToString(tokens.containsKey(heightToken) ? tokens[heightToken]! as num : double.infinity, 0);
181+
return 'const Size($width, $height)';
182+
}
183+
return 'const Size.square(${_numToString(tokens[sizeToken])})';
184+
}
185+
164186
/// Generate a shape constant for the given component token.
165187
///
166188
/// Currently supports family:

packages/flutter/lib/src/material/input_decorator.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -4580,7 +4580,7 @@ class _InputDecoratorDefaultsM3 extends InputDecorationTheme {
45804580

45814581
@override
45824582
TextStyle? get labelStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) {
4583-
final TextStyle textStyle= _textTheme.bodyLarge ?? const TextStyle();
4583+
final TextStyle textStyle = _textTheme.bodyLarge ?? const TextStyle();
45844584
if(states.contains(MaterialState.error)) {
45854585
if (states.contains(MaterialState.focused)) {
45864586
return textStyle.copyWith(color:_colors.error);
@@ -4604,7 +4604,7 @@ class _InputDecoratorDefaultsM3 extends InputDecorationTheme {
46044604

46054605
@override
46064606
TextStyle? get floatingLabelStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) {
4607-
final TextStyle textStyle= _textTheme.bodyLarge ?? const TextStyle();
4607+
final TextStyle textStyle = _textTheme.bodyLarge ?? const TextStyle();
46084608
if(states.contains(MaterialState.error)) {
46094609
if (states.contains(MaterialState.focused)) {
46104610
return textStyle.copyWith(color:_colors.error);
@@ -4628,7 +4628,7 @@ class _InputDecoratorDefaultsM3 extends InputDecorationTheme {
46284628

46294629
@override
46304630
TextStyle? get helperStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) {
4631-
final TextStyle textStyle= _textTheme.bodySmall ?? const TextStyle();
4631+
final TextStyle textStyle = _textTheme.bodySmall ?? const TextStyle();
46324632
if (states.contains(MaterialState.disabled)) {
46334633
return textStyle.copyWith(color:_colors.onSurface.withOpacity(0.38));
46344634
}
@@ -4637,7 +4637,7 @@ class _InputDecoratorDefaultsM3 extends InputDecorationTheme {
46374637

46384638
@override
46394639
TextStyle? get errorStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) {
4640-
final TextStyle textStyle= _textTheme.bodySmall ?? const TextStyle();
4640+
final TextStyle textStyle = _textTheme.bodySmall ?? const TextStyle();
46414641
return textStyle.copyWith(color:_colors.error);
46424642
});
46434643
}

packages/flutter/lib/src/material/material_state.dart

-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ abstract class MaterialStateOutlinedBorder extends OutlinedBorder implements Mat
409409
OutlinedBorder? resolve(Set<MaterialState> states);
410410
}
411411

412-
413412
/// Defines a [TextStyle] that is also a [MaterialStateProperty].
414413
///
415414
/// This class exists to enable widgets with [TextStyle] valued properties

packages/flutter/lib/src/material/menu_anchor.dart

+20-17
Original file line numberDiff line numberDiff line change
@@ -3567,13 +3567,14 @@ bool _platformSupportsAccelerators() {
35673567

35683568
class _MenuBarDefaultsM3 extends MenuStyle {
35693569
_MenuBarDefaultsM3(this.context)
3570-
: super(
3571-
elevation: const MaterialStatePropertyAll<double?>(3.0),
3572-
shape: const MaterialStatePropertyAll<OutlinedBorder>(_defaultMenuBorder),
3573-
alignment: AlignmentDirectional.bottomStart,
3574-
);
3570+
: super(
3571+
elevation: const MaterialStatePropertyAll<double?>(3.0),
3572+
shape: const MaterialStatePropertyAll<OutlinedBorder>(_defaultMenuBorder),
3573+
alignment: AlignmentDirectional.bottomStart,
3574+
);
3575+
35753576
static const RoundedRectangleBorder _defaultMenuBorder =
3576-
RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0)));
3577+
RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0)));
35773578

35783579
final BuildContext context;
35793580

@@ -3609,11 +3610,12 @@ class _MenuBarDefaultsM3 extends MenuStyle {
36093610

36103611
class _MenuButtonDefaultsM3 extends ButtonStyle {
36113612
_MenuButtonDefaultsM3(this.context)
3612-
: super(
3613-
animationDuration: kThemeChangeDuration,
3614-
enableFeedback: true,
3615-
alignment: AlignmentDirectional.centerStart,
3616-
);
3613+
: super(
3614+
animationDuration: kThemeChangeDuration,
3615+
enableFeedback: true,
3616+
alignment: AlignmentDirectional.centerStart,
3617+
);
3618+
36173619
final BuildContext context;
36183620

36193621
late final ColorScheme _colors = Theme.of(context).colorScheme;
@@ -3751,13 +3753,14 @@ class _MenuButtonDefaultsM3 extends ButtonStyle {
37513753

37523754
class _MenuDefaultsM3 extends MenuStyle {
37533755
_MenuDefaultsM3(this.context)
3754-
: super(
3755-
elevation: const MaterialStatePropertyAll<double?>(3.0),
3756-
shape: const MaterialStatePropertyAll<OutlinedBorder>(_defaultMenuBorder),
3757-
alignment: AlignmentDirectional.topEnd,
3758-
);
3756+
: super(
3757+
elevation: const MaterialStatePropertyAll<double?>(3.0),
3758+
shape: const MaterialStatePropertyAll<OutlinedBorder>(_defaultMenuBorder),
3759+
alignment: AlignmentDirectional.topEnd,
3760+
);
3761+
37593762
static const RoundedRectangleBorder _defaultMenuBorder =
3760-
RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0)));
3763+
RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0)));
37613764

37623765
final BuildContext context;
37633766

packages/flutter/lib/src/material/snack_bar.dart

+1-5
Original file line numberDiff line numberDiff line change
@@ -883,10 +883,6 @@ class _SnackbarDefaultsM3 extends SnackBarThemeData {
883883

884884
@override
885885
bool get showCloseIcon => false;
886-
887-
@override
888-
Color get closeIconColor => _colors.onInverseSurface;
889-
}
890-
886+
}
891887

892888
// END GENERATED TOKEN PROPERTIES - Snackbar

packages/flutter/lib/src/material/text_field.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,6 @@ TextStyle _m2CounterErrorStyle(BuildContext context) =>
14291429
TextStyle _m3InputStyle(BuildContext context) => Theme.of(context).textTheme.bodyLarge!;
14301430

14311431
TextStyle _m3CounterErrorStyle(BuildContext context) =>
1432-
Theme.of(context).textTheme.bodySmall!.copyWith(color:Theme.of(context).colorScheme.error);
1432+
Theme.of(context).textTheme.bodySmall!.copyWith(color: Theme.of(context).colorScheme.error);
14331433

14341434
// END GENERATED TOKEN PROPERTIES - TextField

packages/flutter/test/painting/system_fonts_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ void main() {
283283
final RenderObject renderObject = tester.renderObject(
284284
find.descendant(
285285
of: find.byKey(const Key('parent')),
286-
matching: find.byType(CustomPaint),
287-
).first,
286+
matching: find.byKey(const ValueKey<String>('time-picker-dial')),
287+
),
288288
);
289289
expect(renderObject.debugNeedsPaint, isTrue);
290290
});

0 commit comments

Comments
 (0)