Skip to content

Commit c2c2391

Browse files
authored
[material_ui] Migrate M3 InputDecorator template to use new gen_defaults (flutter#13024)
Work toward flutter/flutter#187899. Fixes flutter/flutter#188419. This PR migrates the M3 InputDecorator defaults template to use the new gen_defaults in material_ui. The generated defaults remain unchanged. ## Pre-Review Checklist
1 parent 9316bf0 commit c2c2391

6 files changed

Lines changed: 218 additions & 430 deletions

File tree

packages/material_ui/tool/gen_defaults/temporarily_excluded/generated/input_decorator_defaults.g.dart renamed to packages/material_ui/lib/src/generated/input_decorator_defaults_m3.g.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
// Do not edit by hand. The code is generated from data in the Material
6+
// Design token database by the script:
7+
// packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart.
8+
part of '../input_decorator.dart';
9+
510
class _InputDecoratorDefaultsM3 extends InputDecorationThemeData {
611
_InputDecoratorDefaultsM3(this.context) : super();
712

@@ -44,15 +49,15 @@ class _InputDecoratorDefaultsM3 extends InputDecorationThemeData {
4449
}
4550
if (states.contains(WidgetState.error)) {
4651
if (states.contains(WidgetState.focused)) {
47-
return BorderSide(color: _colors.error, width: 2.0);
52+
return BorderSide(width: 2.0, color: _colors.error);
4853
}
4954
if (states.contains(WidgetState.hovered)) {
5055
return BorderSide(color: _colors.onErrorContainer);
5156
}
5257
return BorderSide(color: _colors.error);
5358
}
5459
if (states.contains(WidgetState.focused)) {
55-
return BorderSide(color: _colors.primary, width: 2.0);
60+
return BorderSide(width: 2.0, color: _colors.primary);
5661
}
5762
if (states.contains(WidgetState.hovered)) {
5863
return BorderSide(color: _colors.onSurface);
@@ -67,15 +72,15 @@ class _InputDecoratorDefaultsM3 extends InputDecorationThemeData {
6772
}
6873
if (states.contains(WidgetState.error)) {
6974
if (states.contains(WidgetState.focused)) {
70-
return BorderSide(color: _colors.error, width: 2.0);
75+
return BorderSide(width: 2.0, color: _colors.error);
7176
}
7277
if (states.contains(WidgetState.hovered)) {
7378
return BorderSide(color: _colors.onErrorContainer);
7479
}
7580
return BorderSide(color: _colors.error);
7681
}
7782
if (states.contains(WidgetState.focused)) {
78-
return BorderSide(color: _colors.primary, width: 2.0);
83+
return BorderSide(width: 2.0, color: _colors.primary);
7984
}
8085
if (states.contains(WidgetState.hovered)) {
8186
return BorderSide(color: _colors.onSurface);

‎packages/material_ui/lib/src/input_decorator.dart‎

Lines changed: 2 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import 'text_theme.dart';
3131
import 'theme.dart';
3232
import 'theme_data.dart';
3333

34+
part 'generated/input_decorator_defaults_m3.g.dart';
35+
3436
// Examples can assume:
3537
// late Widget _myIcon;
3638
// late BuildContext context;
@@ -6017,184 +6019,3 @@ class _InputDecoratorDefaultsM2 extends InputDecorationThemeData {
60176019
};
60186020
});
60196021
}
6020-
6021-
// BEGIN GENERATED TOKEN PROPERTIES - InputDecorator
6022-
6023-
// Do not edit by hand. The code between the "BEGIN GENERATED" and
6024-
// "END GENERATED" comments are generated from data in the Material
6025-
// Design token database by the script:
6026-
// dev/tools/gen_defaults/bin/gen_defaults.dart.
6027-
6028-
// dart format off
6029-
class _InputDecoratorDefaultsM3 extends InputDecorationThemeData {
6030-
_InputDecoratorDefaultsM3(this.context)
6031-
: super();
6032-
6033-
final BuildContext context;
6034-
6035-
late final ColorScheme _colors = Theme.of(context).colorScheme;
6036-
late final TextTheme _textTheme = Theme.of(context).textTheme;
6037-
6038-
// For InputDecorator, focused state should take precedence over hovered state.
6039-
// For instance, the focused state increases border width (2dp) and applies bright
6040-
// colors (primary color or error color) while the hovered state has the same border
6041-
// than the non-focused state (1dp) and uses a color a little darker than non-focused
6042-
// state. On desktop, it is also very common that a text field is focused and hovered
6043-
// because users often rely on mouse selection.
6044-
// For other widgets, hovered state takes precedence over focused state, because it
6045-
// is mainly used to determine the overlay color,
6046-
// see https://github.com/flutter/flutter/pull/125905.
6047-
6048-
@override
6049-
TextStyle? get hintStyle => WidgetStateTextStyle.resolveWith((Set<WidgetState> states) {
6050-
if (states.contains(WidgetState.disabled)) {
6051-
return TextStyle(color: _colors.onSurface.withOpacity(0.38));
6052-
}
6053-
return TextStyle(color: _colors.onSurfaceVariant);
6054-
});
6055-
6056-
@override
6057-
Color? get fillColor => WidgetStateColor.resolveWith((Set<WidgetState> states) {
6058-
if (states.contains(WidgetState.disabled)) {
6059-
return _colors.onSurface.withOpacity(0.04);
6060-
}
6061-
return _colors.surfaceContainerHighest;
6062-
});
6063-
6064-
@override
6065-
BorderSide? get activeIndicatorBorder => WidgetStateBorderSide.resolveWith((Set<WidgetState> states) {
6066-
if (states.contains(WidgetState.disabled)) {
6067-
return BorderSide(color: _colors.onSurface.withOpacity(0.38));
6068-
}
6069-
if (states.contains(WidgetState.error)) {
6070-
if (states.contains(WidgetState.focused)) {
6071-
return BorderSide(color: _colors.error, width: 2.0);
6072-
}
6073-
if (states.contains(WidgetState.hovered)) {
6074-
return BorderSide(color: _colors.onErrorContainer);
6075-
}
6076-
return BorderSide(color: _colors.error);
6077-
}
6078-
if (states.contains(WidgetState.focused)) {
6079-
return BorderSide(color: _colors.primary, width: 2.0);
6080-
}
6081-
if (states.contains(WidgetState.hovered)) {
6082-
return BorderSide(color: _colors.onSurface);
6083-
}
6084-
return BorderSide(color: _colors.onSurfaceVariant);
6085-
});
6086-
6087-
@override
6088-
BorderSide? get outlineBorder => WidgetStateBorderSide.resolveWith((Set<WidgetState> states) {
6089-
if (states.contains(WidgetState.disabled)) {
6090-
return BorderSide(color: _colors.onSurface.withOpacity(0.12));
6091-
}
6092-
if (states.contains(WidgetState.error)) {
6093-
if (states.contains(WidgetState.focused)) {
6094-
return BorderSide(color: _colors.error, width: 2.0);
6095-
}
6096-
if (states.contains(WidgetState.hovered)) {
6097-
return BorderSide(color: _colors.onErrorContainer);
6098-
}
6099-
return BorderSide(color: _colors.error);
6100-
}
6101-
if (states.contains(WidgetState.focused)) {
6102-
return BorderSide(color: _colors.primary, width: 2.0);
6103-
}
6104-
if (states.contains(WidgetState.hovered)) {
6105-
return BorderSide(color: _colors.onSurface);
6106-
}
6107-
return BorderSide(color: _colors.outline);
6108-
});
6109-
6110-
@override
6111-
Color? get iconColor => _colors.onSurfaceVariant;
6112-
6113-
@override
6114-
Color? get prefixIconColor => WidgetStateColor.resolveWith((Set<WidgetState> states) {
6115-
if (states.contains(WidgetState.disabled)) {
6116-
return _colors.onSurface.withOpacity(0.38);
6117-
}
6118-
return _colors.onSurfaceVariant;
6119-
});
6120-
6121-
@override
6122-
Color? get suffixIconColor => WidgetStateColor.resolveWith((Set<WidgetState> states) {
6123-
if (states.contains(WidgetState.disabled)) {
6124-
return _colors.onSurface.withOpacity(0.38);
6125-
}
6126-
if (states.contains(WidgetState.error)) {
6127-
if (states.contains(WidgetState.hovered)) {
6128-
return _colors.onErrorContainer;
6129-
}
6130-
return _colors.error;
6131-
}
6132-
return _colors.onSurfaceVariant;
6133-
});
6134-
6135-
@override
6136-
TextStyle? get labelStyle => WidgetStateTextStyle.resolveWith((Set<WidgetState> states) {
6137-
final TextStyle textStyle = _textTheme.bodyLarge ?? const TextStyle();
6138-
if (states.contains(WidgetState.disabled)) {
6139-
return textStyle.copyWith(color: _colors.onSurface.withOpacity(0.38));
6140-
}
6141-
if (states.contains(WidgetState.error)) {
6142-
if (states.contains(WidgetState.focused)) {
6143-
return textStyle.copyWith(color: _colors.error);
6144-
}
6145-
if (states.contains(WidgetState.hovered)) {
6146-
return textStyle.copyWith(color: _colors.onErrorContainer);
6147-
}
6148-
return textStyle.copyWith(color: _colors.error);
6149-
}
6150-
if (states.contains(WidgetState.focused)) {
6151-
return textStyle.copyWith(color: _colors.primary);
6152-
}
6153-
if (states.contains(WidgetState.hovered)) {
6154-
return textStyle.copyWith(color: _colors.onSurfaceVariant);
6155-
}
6156-
return textStyle.copyWith(color: _colors.onSurfaceVariant);
6157-
});
6158-
6159-
@override
6160-
TextStyle? get floatingLabelStyle => WidgetStateTextStyle.resolveWith((Set<WidgetState> states) {
6161-
final TextStyle textStyle = _textTheme.bodyLarge ?? const TextStyle();
6162-
if (states.contains(WidgetState.disabled)) {
6163-
return textStyle.copyWith(color: _colors.onSurface.withOpacity(0.38));
6164-
}
6165-
if (states.contains(WidgetState.error)) {
6166-
if (states.contains(WidgetState.focused)) {
6167-
return textStyle.copyWith(color: _colors.error);
6168-
}
6169-
if (states.contains(WidgetState.hovered)) {
6170-
return textStyle.copyWith(color: _colors.onErrorContainer);
6171-
}
6172-
return textStyle.copyWith(color: _colors.error);
6173-
}
6174-
if (states.contains(WidgetState.focused)) {
6175-
return textStyle.copyWith(color: _colors.primary);
6176-
}
6177-
if (states.contains(WidgetState.hovered)) {
6178-
return textStyle.copyWith(color: _colors.onSurfaceVariant);
6179-
}
6180-
return textStyle.copyWith(color: _colors.onSurfaceVariant);
6181-
});
6182-
6183-
@override
6184-
TextStyle? get helperStyle => WidgetStateTextStyle.resolveWith((Set<WidgetState> states) {
6185-
final TextStyle textStyle = _textTheme.bodySmall ?? const TextStyle();
6186-
if (states.contains(WidgetState.disabled)) {
6187-
return textStyle.copyWith(color: _colors.onSurface.withOpacity(0.38));
6188-
}
6189-
return textStyle.copyWith(color: _colors.onSurfaceVariant);
6190-
});
6191-
6192-
@override
6193-
TextStyle? get errorStyle => WidgetStateTextStyle.resolveWith((Set<WidgetState> states) {
6194-
final TextStyle textStyle = _textTheme.bodySmall ?? const TextStyle();
6195-
return textStyle.copyWith(color: _colors.error);
6196-
});
6197-
}
6198-
// dart format on
6199-
6200-
// END GENERATED TOKEN PROPERTIES - InputDecorator

‎packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ import '../templates/filter_chip_template.dart';
3333
import '../templates/icon_button_template.dart';
3434
import '../templates/input_chip_template.dart';
3535

36-
// import '../templates/input_decorator_template.dart';
36+
import '../templates/input_decorator_template.dart';
37+
3738
// import '../templates/list_tile_template.dart';
3839
// import '../templates/menu_template.dart';
3940
// import '../templates/motion_template.dart';
@@ -95,7 +96,7 @@ Future<void> main(List<String> args) async {
9596
const IconButtonTemplateM3E('Filled Tonal Icon Button').generateFile(verbose: verbose);
9697
const IconButtonTemplateM3E('Outlined Icon Button').generateFile(verbose: verbose);
9798
const InputChipTemplateM3().generateFile(verbose: verbose);
98-
// const InputDecoratorTemplateM3().generateFile(verbose: verbose);
99+
const InputDecoratorTemplateM3().generateFile(verbose: verbose);
99100
// const ListTileTemplateM3().generateFile(verbose: verbose);
100101
// const MenuTemplateM3().generateFile(verbose: verbose);
101102
// const MotionTemplateM3().generateFile(verbose: verbose);

0 commit comments

Comments
 (0)