-
Notifications
You must be signed in to change notification settings - Fork 28.7k
Migrate InputDecorator to Material 3 #107943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good and the results look good too. One bit of feedback that I didn't leave everywhere: sometimes the original defaults code stayed roughly the same, in others it applied resolveAs to a MaterialStateColor. The code might be easier to understand if we were consistent about that; it seems like in most cases we could encode the M2 defaults a MaterialStateColor, MaterialStateBorderSide, MaterialStateTextStyle.
} | ||
|
||
/// An example of the filled text field type. | ||
class FilledTextFieldExample extends StatelessWidget { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment, and the similar one below, might be a good place to link to the M3 spec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added spec link
|
||
@override | ||
BorderSide? get activeIndicatorBorder => MaterialStateBorderSide.resolveWith((Set<MaterialState> states) { | ||
if (states.contains(MaterialState.error)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In code like this, maybe create a local variable:
final ColorScheme colorScheme = Theme.of(context).colorScheme;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The theme code here is generated by gen_defaults.dart
Maybe I will update the generator script to support local variable in a separated PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Although these lookups are cheap, it might be worth updating the code generator in another PR (as you've pointed out).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It actually already does (but perhaps not well documented 😎). Each template can define a prefix for the color scheme and text theme, which can be set to the name of a local variable defined in the body of the template:
flutter/dev/tools/gen_defaults/lib/dialog_template.dart
Lines 8 to 10 in fa56180
const DialogTemplate(super.blockName, super.fileName, super.tokens, { | |
super.colorSchemePrefix = '_colors.', | |
super.textThemePrefix = '_textTheme.' |
and
flutter/dev/tools/gen_defaults/lib/dialog_template.dart
Lines 23 to 25 in fa56180
final BuildContext context; | |
late final ColorScheme _colors = Theme.of(context).colorScheme; | |
late final TextTheme _textTheme = Theme.of(context).textTheme; |
Which will then do the right thing when using the componentColor
and textStyle
methods in the rest of the template.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for letting me know!
Good point! So In the latest commit, I encoded most M2 default properties (colors and textStyles) as MaterialStateColor and MaterialStateTextStyle. As for borders, _getDefaultM2BorderColor is not encoded because it is using decoration's property(decoration.hoverColor). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
if (isFocused) { | ||
return themeData.colorScheme.primary; | ||
Color _getDefaultM2BorderColor(ThemeData themeData) { | ||
if(!decoration.enabled && !isFocused){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need a space between if
and (
. Here and elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
TextStyle? get inputStyle => Theme.of(context).textTheme.subtitle1; | ||
|
||
@override | ||
TextStyle? get hintStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a future PR, you could optimize the cases where a closure isn't need (like all of them?):
TextStyle? getHintStyle(Set<MaterialState> states) {
if (states.contains(MaterialState.disabled)) {
return TextStyle(color: Theme.of(context).disabledColor);
}
return TextStyle(color: Theme.of(context).hintColor);
}
TextStyle? get hintStyle => MaterialStateTextStyle.resolveWith(getHintStyle);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Nice work on a complicated widget.
I have a few suggestions and comments below. They can be addressed in a followup PR if you like.
|
||
@override | ||
BorderSide? get activeIndicatorBorder => MaterialStateBorderSide.resolveWith((Set<MaterialState> states) { | ||
if (states.contains(MaterialState.error)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It actually already does (but perhaps not well documented 😎). Each template can define a prefix for the color scheme and text theme, which can be set to the name of a local variable defined in the body of the template:
flutter/dev/tools/gen_defaults/lib/dialog_template.dart
Lines 8 to 10 in fa56180
const DialogTemplate(super.blockName, super.fileName, super.tokens, { | |
super.colorSchemePrefix = '_colors.', | |
super.textThemePrefix = '_textTheme.' |
and
flutter/dev/tools/gen_defaults/lib/dialog_template.dart
Lines 23 to 25 in fa56180
final BuildContext context; | |
late final ColorScheme _colors = Theme.of(context).colorScheme; | |
late final TextTheme _textTheme = Theme.of(context).textTheme; |
Which will then do the right thing when using the componentColor
and textStyle
methods in the rest of the template.
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// Flutter code sample for TextField |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have other examples for TextField, then we might want to call this out as a sample for Material Design 3 TextFields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} | ||
else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: the else should be on the same line with the }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -4223,6 +4214,8 @@ class InputDecorationTheme with Diagnosticable { | |||
filled, | |||
Object.hash( | |||
fillColor, | |||
activeIndicatorBorder, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like inputStyle
is missing here and other places below. Please verify that all three added fields are accounted for in each of the boilerplate methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
* 2142b2e Roll Flutter Engine from cd7e2ec4037b to c31036f2381c (1 revision) (flutter/flutter#108299) * 178e444 Revert "Add optional flag to determine assertiveness level in aria announcement for flutter web" (flutter/flutter#108262) * 8a7b359 flutter update-packages --force-upgrade + analyzer fix (flutter/flutter#108198) * b3f5d3f Roll Flutter Engine from c31036f2381c to 54b0ac3059bf (1 revision) (flutter/flutter#108302) * 2f4299a [flutter_tools] Remove unused parameter when connected DAP to VM Service (flutter/flutter#108285) * e74b9b5 Migrate InputDecorator to Material 3 (flutter/flutter#107943) * e3b851a Fix Tamil DateTime representation of AM/PM (flutter/flutter#108185) * 43d6e2b Roll Flutter Engine from 54b0ac3059bf to 705072522c00 (4 revisions) (flutter/flutter#108308) * 6929ad1 Roll Flutter Engine from 705072522c00 to 3964cf62cdf8 (1 revision) (flutter/flutter#108316) * 5f67b47 [iOS] Update template icons (flutter/flutter#107873) * 606954d Added iconSize parameter in ButtonStyle (flutter/flutter#108268) * b3814c7 Roll Flutter Engine from 3964cf62cdf8 to 7f8925b1f6f3 (2 revisions) (flutter/flutter#108320) * ca6cecf Upgrade Gradle and AGP versions to 7.5/7.2 and migrate examples/tests (flutter/flutter#108197) * d155bc1 Revert "Upgrade Gradle and AGP versions to 7.5/7.2 and migrate examples/tests (#108197)" (flutter/flutter#108349) * 4056d3f Explain the "patching" protocol in `KeyMessageManager.keyMessageHandler` and add an example (flutter/flutter#105280) * b035ef1 [flutter_tools] Remove more shuffles (flutter/flutter#107759) * be14858 Roll Flutter Engine from 7f8925b1f6f3 to 8eca26d130a2 (1 revision) (flutter/flutter#108326) * 3eb638f Roll Flutter Engine from 8eca26d130a2 to f1f9b4de82b6 (5 revisions) (flutter/flutter#108350) * 401b556 Roll Flutter Engine from f1f9b4de82b6 to 11d927ac3e9b (2 revisions) (flutter/flutter#108353) * 925bee9 Roll Flutter Engine from 11d927ac3e9b to 5dcaeae6561b (1 revision) (flutter/flutter#108356) * 5d31b07 [flutter_tools] [dap] Ensure DAP sends app.stop/app.detach during terminate (flutter/flutter#108310) * c8b5d10 Roll Flutter Engine from 5dcaeae6561b to 89e117b89c63 (1 revision) (flutter/flutter#108367) * e3d08fb Hide the debug banner in the PopupMenuButton example (flutter/flutter#108324)
* Support material 3 in inputDecorator * Format polish * format polish * update input_decorator_test * revert pub * style update * style polish * default before base * resolve comments * Update text_field.2.dart * move text styles into M2 theme * add error style * fix typo * resolve comments * fix g3 test
* 2142b2e Roll Flutter Engine from cd7e2ec4037b to c31036f2381c (1 revision) (flutter/flutter#108299) * 178e444 Revert "Add optional flag to determine assertiveness level in aria announcement for flutter web" (flutter/flutter#108262) * 8a7b359 flutter update-packages --force-upgrade + analyzer fix (flutter/flutter#108198) * b3f5d3f Roll Flutter Engine from c31036f2381c to 54b0ac3059bf (1 revision) (flutter/flutter#108302) * 2f4299a [flutter_tools] Remove unused parameter when connected DAP to VM Service (flutter/flutter#108285) * e74b9b5 Migrate InputDecorator to Material 3 (flutter/flutter#107943) * e3b851a Fix Tamil DateTime representation of AM/PM (flutter/flutter#108185) * 43d6e2b Roll Flutter Engine from 54b0ac3059bf to 705072522c00 (4 revisions) (flutter/flutter#108308) * 6929ad1 Roll Flutter Engine from 705072522c00 to 3964cf62cdf8 (1 revision) (flutter/flutter#108316) * 5f67b47 [iOS] Update template icons (flutter/flutter#107873) * 606954d Added iconSize parameter in ButtonStyle (flutter/flutter#108268) * b3814c7 Roll Flutter Engine from 3964cf62cdf8 to 7f8925b1f6f3 (2 revisions) (flutter/flutter#108320) * ca6cecf Upgrade Gradle and AGP versions to 7.5/7.2 and migrate examples/tests (flutter/flutter#108197) * d155bc1 Revert "Upgrade Gradle and AGP versions to 7.5/7.2 and migrate examples/tests (#108197)" (flutter/flutter#108349) * 4056d3f Explain the "patching" protocol in `KeyMessageManager.keyMessageHandler` and add an example (flutter/flutter#105280) * b035ef1 [flutter_tools] Remove more shuffles (flutter/flutter#107759) * be14858 Roll Flutter Engine from 7f8925b1f6f3 to 8eca26d130a2 (1 revision) (flutter/flutter#108326) * 3eb638f Roll Flutter Engine from 8eca26d130a2 to f1f9b4de82b6 (5 revisions) (flutter/flutter#108350) * 401b556 Roll Flutter Engine from f1f9b4de82b6 to 11d927ac3e9b (2 revisions) (flutter/flutter#108353) * 925bee9 Roll Flutter Engine from 11d927ac3e9b to 5dcaeae6561b (1 revision) (flutter/flutter#108356) * 5d31b07 [flutter_tools] [dap] Ensure DAP sends app.stop/app.detach during terminate (flutter/flutter#108310) * c8b5d10 Roll Flutter Engine from 5dcaeae6561b to 89e117b89c63 (1 revision) (flutter/flutter#108367) * e3d08fb Hide the debug banner in the PopupMenuButton example (flutter/flutter#108324)
* 2142b2e Roll Flutter Engine from cd7e2ec4037b to c31036f2381c (1 revision) (flutter/flutter#108299) * 178e444 Revert "Add optional flag to determine assertiveness level in aria announcement for flutter web" (flutter/flutter#108262) * 8a7b359 flutter update-packages --force-upgrade + analyzer fix (flutter/flutter#108198) * b3f5d3f Roll Flutter Engine from c31036f2381c to 54b0ac3059bf (1 revision) (flutter/flutter#108302) * 2f4299a [flutter_tools] Remove unused parameter when connected DAP to VM Service (flutter/flutter#108285) * e74b9b5 Migrate InputDecorator to Material 3 (flutter/flutter#107943) * e3b851a Fix Tamil DateTime representation of AM/PM (flutter/flutter#108185) * 43d6e2b Roll Flutter Engine from 54b0ac3059bf to 705072522c00 (4 revisions) (flutter/flutter#108308) * 6929ad1 Roll Flutter Engine from 705072522c00 to 3964cf62cdf8 (1 revision) (flutter/flutter#108316) * 5f67b47 [iOS] Update template icons (flutter/flutter#107873) * 606954d Added iconSize parameter in ButtonStyle (flutter/flutter#108268) * b3814c7 Roll Flutter Engine from 3964cf62cdf8 to 7f8925b1f6f3 (2 revisions) (flutter/flutter#108320) * ca6cecf Upgrade Gradle and AGP versions to 7.5/7.2 and migrate examples/tests (flutter/flutter#108197) * d155bc1 Revert "Upgrade Gradle and AGP versions to 7.5/7.2 and migrate examples/tests (#108197)" (flutter/flutter#108349) * 4056d3f Explain the "patching" protocol in `KeyMessageManager.keyMessageHandler` and add an example (flutter/flutter#105280) * b035ef1 [flutter_tools] Remove more shuffles (flutter/flutter#107759) * be14858 Roll Flutter Engine from 7f8925b1f6f3 to 8eca26d130a2 (1 revision) (flutter/flutter#108326) * 3eb638f Roll Flutter Engine from 8eca26d130a2 to f1f9b4de82b6 (5 revisions) (flutter/flutter#108350) * 401b556 Roll Flutter Engine from f1f9b4de82b6 to 11d927ac3e9b (2 revisions) (flutter/flutter#108353) * 925bee9 Roll Flutter Engine from 11d927ac3e9b to 5dcaeae6561b (1 revision) (flutter/flutter#108356) * 5d31b07 [flutter_tools] [dap] Ensure DAP sends app.stop/app.detach during terminate (flutter/flutter#108310) * c8b5d10 Roll Flutter Engine from 5dcaeae6561b to 89e117b89c63 (1 revision) (flutter/flutter#108367) * e3d08fb Hide the debug banner in the PopupMenuButton example (flutter/flutter#108324)
issue:#103537
Migrate InputDecorator to Material 3, including fillColor, boderColor, iconColor, label text style, supporting text style.
Will migrate the input text style in a separated PR because it's in TextField, not the InputDecorator.
Pre-launch Checklist
///
).