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

Skip to content

Deprecate ThemeData.errorColor and ThemeData.backgroundColor #94156

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

Closed
wants to merge 7 commits into from
Closed

Deprecate ThemeData.errorColor and ThemeData.backgroundColor #94156

wants to merge 7 commits into from

Conversation

guidezpl
Copy link
Member

@guidezpl guidezpl commented Nov 24, 2021

In line with https://flutter.dev/go/material-theme-system-updates and #91772, deprecates redundant ThemeData properties.

Old New Previous usages
ThemeData.errorColor ColorScheme.error TextField error states
ThemeData.backgroundColor ColorScheme.background was unused

A Dart fix is provided.

This is not a breaking change, per our policy.

@flutter-dashboard flutter-dashboard bot added a: text input Entering text in a text field or keyboard related problems 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 Nov 24, 2021
@google-cla google-cla bot added the cla: yes label Nov 24, 2021
@flutter-dashboard flutter-dashboard bot added f: routes Navigator, Router, and related APIs. c: tech-debt Technical debt, code quality, testing, etc. labels Nov 26, 2021
@Piinks
Copy link
Contributor

Piinks commented Nov 29, 2021

I am wondering if this is a bug with dart fix itself, cc @bwilkerson
As I understand it, there is a rule to fix backgroundColor, and another rule to fix errorColor, but when backgroundColor and errorColor are both being used, only one of the rules is being applied.
I am going to see if I can reproduce this tomorrow in a smaller test case, and if so I'll file a bug and link it back here. I'll follow up tomorrow.

@bwilkerson
Copy link
Contributor

It's certainly possible that there's a bug, but I think there's a different reason for what you're seeing.

When the transforms (the things with titles) in the fix_data.yaml file are applied, they are applied sequentially, one at a time. That is, each transform is independent of the others.

When the transform for errorColor runs it produces the edits you're seeing. When the transform for backgroundColor runs, it produces a similar set of edits, but those edits aren't applied because the framework detects that they conflict with the first set of edits (from the errorColor transform). In order to prevent user code from being corrupted, the framework discards the second set of edits and then continues looking for other problems to fix.

I recently (11/23) updated dart fix so that it now runs in a loop:

compute the edits for as many fixes as possible
while (there are edits to be applied) {
  apply the edits to the files
  re-analyze all the changed files
  compute the edits for as many fixes as possible
}

I'm guessing that this change hasn't yet rolled from the Dart SDK into Flutter. When it does I believe that it ought to fix this problem.

We could confirm that hypothesis by taking the output from the first run of dart fix and run dart fix over it again (manually iterate). If the edits for backgroundColor are applied on the second run, then the change ought to solve the problem.

@Piinks
Copy link
Contributor

Piinks commented Dec 1, 2021

Thank you very much @bwilkerson! That makes a lot of sense.
@guidezpl it looks lie this has not been synced with master since that change was made, can you update and we can see if this is already fixed? :)

@markusaksli-nc
Copy link
Contributor

markusaksli-nc commented Jan 20, 2022

@guidezpl I was actually looking into deprecating errorColor myself, do you plan to proceed with this PR?

FYI #87868

@guidezpl
Copy link
Member Author

Thanks @bwilkerson and @Piinks! I tried it out and it did indeed apply both fixes. However (expectedly), it creates an additional copyWith. I wonder if this can this be improved?

  // Changes mades in https://github.com/flutter/flutter/pull/94156
  ThemeData themeData = ThemeData();
  themeData = ThemeData(colorScheme: ColorScheme.fromSwatch().copyWith(error: Colors.red).copyWith(background: Colors.grey));
  themeData = ThemeData.raw(colorScheme: ColorScheme.fromSwatch().copyWith(error: Colors.red).copyWith(background: Colors.grey));
  themeData = themeData.copyWith(colorScheme: ColorScheme.fromSwatch().copyWith(error: Colors.red).copyWith(background: Colors.grey));

@markusaksli-nc yes, I'll let #95870 land first and then get this one in.

name: 'colorScheme'
style: optional_named
argumentValue:
expression: '{% colorScheme %}.copyWith(background: {% backgroundColor %})'
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is why an additional copyWith is being added.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was able to simplify the output a little bit, but couldn't find a way to avoid the additional copyWith in the case where both colors are present. I think it's still a fine change.

@flutter-dashboard flutter-dashboard bot added d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos documentation labels Mar 16, 2022
@guidezpl guidezpl removed the cla: yes label May 1, 2022
@guidezpl
Copy link
Member Author

guidezpl commented Jun 3, 2022

No cycles to finish this at the moment, will get to it eventually.

@guidezpl guidezpl reopened this Aug 5, 2022
@guidezpl guidezpl marked this pull request as ready for review August 24, 2022 09:22
@guidezpl
Copy link
Member Author

guidezpl commented Aug 24, 2022

Can't get the new commits to appear, will close and reopen a new pull request: #110162

@guidezpl guidezpl closed this Aug 24, 2022
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. c: tech-debt Technical debt, code quality, testing, etc. d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos f: material design flutter/packages/flutter/material repository. f: routes Navigator, Router, and related APIs. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants