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

Skip to content

Refactor ThemeData #91497

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 29 commits into from
Oct 29, 2021
Merged

Refactor ThemeData #91497

merged 29 commits into from
Oct 29, 2021

Conversation

guidezpl
Copy link
Member

@guidezpl guidezpl commented Oct 8, 2021

I was trying to make sense of the ThemeData class and thought it could be improved with some categorisation of parameters and alphabetical sorting.

  • Categorizes properties with comment headers to easily find all the places where they should be kept in order
    • Alphabetization used where helpful
    • Deprecated properties get their own category, and are sorted from oldest to newest
  • Adds missing documentation about platform defining defaults for typography and materialTapTargetSize

This should help future additions and deprecations, while making it easier for developers to inspect and understand.

Related issues

#91772

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.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Oct 8, 2021
@guidezpl guidezpl requested a review from HansMuller October 8, 2021 16:10
@google-cla google-cla bot added the cla: yes label Oct 8, 2021
@HansMuller
Copy link
Contributor

This is likely to be a rather tedious undertaking, since all of the parameter lists in theme_data.dart are supposed to be in the same order (for our own sanity). If you're going to categorize the theme data properties, it would be helpful to highlight the ones whose lifetime is limited per flutter.dev/go/material-theme-system-updates and the upcoming move to Material 3.

That said, if you'd really like to improve the readability of this file, go for it.

@guidezpl
Copy link
Member Author

I'm torn between my laziness and love for neatness. I think I'll do just categorization and forgo alphabetization

@guidezpl guidezpl changed the title Re-organize ThemeData Refactor ThemeData Oct 13, 2021
@guidezpl guidezpl requested a review from rami-a October 13, 2021 22:03
@guidezpl
Copy link
Member Author

guidezpl commented Oct 13, 2021

@HansMuller I went ahead and did the whole thing. Don't ever make me do that again (kidding)

@rami-a Can you provide color (ha) into which color properties–if any–will be repurposed for material 3? #89852

Also, I'll add tests for debugFillProperties

@guidezpl guidezpl marked this pull request as ready for review October 13, 2021 22:05
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@darrenaustin
Copy link
Contributor

@guidezpl, sorry I didn't catch this sooner. I thought you were just updating the parameters to the default constructor. I was also working in this area with #91774 which will now likely conflict with anything you do in the rest of the file. We should coordinate so we don't step on each others changes.

As for which colors will be repurposed for M3, none of the top level color parameters in the ThemeData will be needed, as they are mostly just for backwards compatibility at this point. M3 will be using the colors from the colorScheme exclusively.

@guidezpl
Copy link
Member Author

Np, please merge your change first, it'll easier for me to merge it into mine afterwards.

That was my understanding as well, sounds good.

@darrenaustin
Copy link
Contributor

Np, please merge your change first, it'll easier for me to merge it into mine afterwards.

Will do. Unfortunately there was a revert on master that is causing a merge issue for my PR. Once I get that sorted out I will land it this morning.

@guidezpl
Copy link
Member Author

guidezpl commented Oct 25, 2021

I noticed that platform defines defaults for typography and materialTapTargetSize but wasn't documented. I added missing explanations

@HansMuller I'm running into a failed test for the backwards compatibility for deprecated buttons' highlight color. e.g. In theme_defaults_test.dart, a RaisedButton is expected to have a highlight color of 0x29000000, but I'm getting 0x66bcbcbc. This is noted in the comments as "// Was Color(0x66bcbcbc)". Can you help me understand this change in default?

@HansMuller
Copy link
Contributor

The line you're referring to was added about 3 years ago (https://github.com/flutter/flutter/pull/22013/files#diff-7ba6209c92d2c9f5eaedb3ae9336f9c7049aedff35e18c697150a64317fd79e7R31) and I don't think I can offer an explanation for that. I assume that something is slightly out of order WRT the ThemeData initializations, but couldn't tell you more without really digging in.

@guidezpl
Copy link
Member Author

Thanks, fixed that. Good to review

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

This definitely improves readability.

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 as well. This was a tedious task, thanks for taking it on.

@guidezpl guidezpl merged commit 78689d3 into flutter:master Oct 29, 2021
@guidezpl guidezpl deleted the themedaata branch October 29, 2021 06:33
clocksmith pushed a commit to clocksmith/flutter that referenced this pull request Oct 29, 2021
guidezpl added a commit that referenced this pull request Nov 1, 2021
@rydmike
Copy link
Contributor

rydmike commented Nov 1, 2021

Wow, thanks @guidezpl! For us that reads ThemeData a lot this is really useful and nice! 💙

WizzXu pushed a commit to WizzXu/flutter that referenced this pull request Nov 19, 2021
WizzXu pushed a commit to WizzXu/flutter that referenced this pull request Nov 19, 2021
WizzXu pushed a commit to WizzXu/flutter that referenced this pull request Nov 19, 2021
WizzXu pushed a commit to WizzXu/flutter that referenced this pull request Nov 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

6 participants