Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 16 commits into from
Jul 25, 2022
Merged

Conversation

hannah-hyj
Copy link
Member

@hannah-hyj hannah-hyj commented Jul 19, 2022

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.

Screenshot_20220719-235150

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added a: text input Entering text in a text field or keyboard related problems d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos documentation f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. c: contributor-productivity Team-specific productivity, code health, technical debt. labels Jul 19, 2022
@hannah-hyj hannah-hyj changed the title Support material 3 in inputDecorator Migrate InputDecorator to Material 3 Jul 19, 2022
Copy link
Contributor

@HansMuller HansMuller left a 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 {
Copy link
Contributor

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

Copy link
Member Author

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)) {
Copy link
Contributor

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;

Copy link
Member Author

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.

Copy link
Contributor

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).

Copy link
Contributor

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:

const DialogTemplate(super.blockName, super.fileName, super.tokens, {
super.colorSchemePrefix = '_colors.',
super.textThemePrefix = '_textTheme.'

and

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.

Copy link
Member Author

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!

@hannah-hyj
Copy link
Member Author

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.

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).

@hannah-hyj hannah-hyj requested a review from HansMuller July 22, 2022 15:21
Copy link
Contributor

@HansMuller HansMuller left a 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){
Copy link
Contributor

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.

Copy link
Member Author

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) {
Copy link
Contributor

@HansMuller HansMuller Jul 22, 2022

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);

Copy link
Contributor

@darrenaustin darrenaustin left a 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)) {
Copy link
Contributor

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:

const DialogTemplate(super.blockName, super.fileName, super.tokens, {
super.colorSchemePrefix = '_colors.',
super.textThemePrefix = '_textTheme.'

and

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
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 2095 to 2096
}
else {
Copy link
Contributor

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 }

Copy link
Member Author

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,
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@hannah-hyj hannah-hyj deleted the branch2 branch July 25, 2022 17:36
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 25, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 25, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 25, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Jul 26, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 26, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 26, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 26, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 26, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 26, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 26, 2022
stuartmorgan-g pushed a commit to flutter/plugins that referenced this pull request Jul 27, 2022
* 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)
camsim99 pushed a commit to camsim99/flutter that referenced this pull request Aug 10, 2022
* 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
yutaaraki-toydium pushed a commit to yutaaraki-toydium/plugins that referenced this pull request Aug 12, 2022
* 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)
mauricioluz pushed a commit to mauricioluz/plugins that referenced this pull request Jan 26, 2023
* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: text input Entering text in a text field or keyboard related problems c: contributor-productivity Team-specific productivity, code health, technical debt. d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants