Skip to content

☂️ Material Theme System Updates #91772

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

Open
25 of 42 tasks
Tracked by #91605
guidezpl opened this issue Oct 13, 2021 · 22 comments
Open
25 of 42 tasks
Tracked by #91605

☂️ Material Theme System Updates #91772

guidezpl opened this issue Oct 13, 2021 · 22 comments
Labels
c: tech-debt Technical debt, code quality, testing, etc. f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. P2 Important issues not at the top of the work list team-design Owned by Design Languages team triaged-design Triaged by Design Languages team

Comments

@guidezpl
Copy link
Member

guidezpl commented Oct 13, 2021

This issue mirrors the design of https://flutter.dev/go/material-theme-system-updates

Rename the TextTheme TextStyles

Deprecate/remove the accent properties

Compute brightness, primaryColorBrightness, accentColorBrightness

Deprecate/move/remove the 21 grab-bag properties

(x) indicates number of references, excludingtheme_data.dart and tests. This can be used a proxy for disruptiveness/ease of deprecation.

Additional grab-bag properties

These grab-bag properties not in the original linked proposal, but can also be deprecated:

These factory constructor parameters can also be deprecated:

Property colors not subject to removal

  • State colors like ThemeData.disabledColor (26), ThemeData.focusColor (19), and ThemeData.hoverColor (19) have high usage and are shared amongst many components
  • There is similar widespread usage for ThemeData.highlightColor (13)
  • Other parameters can remain in the factory constructor (e.g. ThemeData.fontFamily and ThemeData.fontFamilyFallback) for convenience

Component Theme Normalization

All of the existing themes have been normalized except for the following:

@guidezpl guidezpl mentioned this issue Oct 13, 2021
8 tasks
@danagbemava-nc danagbemava-nc added in triage Presently being triaged by the triage team f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. passed first triage and removed in triage Presently being triaged by the triage team labels Oct 14, 2021
@rydmike
Copy link
Contributor

rydmike commented Nov 10, 2021

Nice summary @guidezpl and great to see this collection issue for moving this topic forward and tracking its progress. It will certainly make things clearer when completed. The current situation seems to be a source of a lot of confusion for many Flutter developers, quite a few related issues open and more arriving ever so often. This will help, eventually.

Most of the colors properties already have proper homes in the ColorScheme and/or appropriate sub-themes, where you can override widget default inherited colors, that properly designed SDK Material UI widgets now get from ThemeData.colorScheme.

For those colors everything looks fine, but not all color properties in ThemeData are so lucky and at that stage. Below I highlight one important case: scaffoldBackgroundColor, there might be others too.

Things to Consider during the Theme System Update and Migration

In case it is not obvious, but as far as I know e.g. ThemeData.scaffoldBackgroundColor currently does not have a home anywhere else. If you do not want it to be same color as ThemeData.colorScheme.background, which presumably would be its new default, ThemeData.from() already assigns this color to it. Then there is no other way to currently theme it.

The only way to set it separately, is to define the ThemeData.scaffoldBackgroundColor, so it needs a new home somewhere.

Being able define slightly different background colors depending on type of surface/background is important. It makes it possible in current version of Flutter to create applications that uses background colors with slightly different nuances, typically with different alpha blend strengths of primary color in the different surface/background colors used by Widgets, depending on their type and current default themed color behavior.

For example, currently with the factory ThemeData.from, that is the most up to date one of the color factories for using proper ColorScheme based themes, we for example have:

  • colorScheme.surface, that is assigned to cardColor, used by Card and Material of type card. Expecting these widgets to use colorScheme.surface directly after migration. This is fine and will not hard break anything, change can imo be done easily, everything looks ready for it.
  • colorScheme.background, that is assigned to canvasColor, used by Material of type canvas, and via that many widgets. Expecting Material of type canvas to use colorScheme.background directly after migration. This is fine and will not hard break anything, change can imo be done easily, everything looks ready for it.
  • dialogBackgroundColor that gets assigned colorScheme.background, already has its own sub-theme, so we can easily theme it to whatever we like (we already use that route in anticipation of dialogBackgroundColor deprecation. This prop can imo be deprecated easily already now, migration path is clear/ready.
  • scaffoldBackgroundColor, is also assigned colorScheme.background, but has no other source that can be used to theme it, other than the current ThemeData. It will need it's own new sub-theme, otherwise scaffoldBackgroundColor cannot be deprecated without reduction in currently used theming capabilities and flexibility. It would break things very badly in our apps if it cannot be themed to another color than ThemeData.colorScheme.background going forward.

This might apply to a few other ThemeData color properties on the deprecation list as well.

PS. Yes, I'm aware Material3 brings new containers used for color and onColor, so it will have less/none of these current messy issue that many Flutter devs struggle with when it comes to theme colors for Flutter apps. Although I suspect many will think that M3 color design might be a bit complex. I think it seems pretty straight forward and makes a lot of sense. Looking forward to see how it gets implemented in Flutter. Might be a bit tricky with backward compatibility issues and potential challenges merging it with current widgets. Plus it will increase widget branching for color logic and calculation, potentially decreasing performance of current widgets. Hopefully not, will be interesting to see what the chosen approach is. Just new M3 widgets that uses new Theme designs and concepts, might be simplest, but not ideal either.

@talamaska
Copy link
Contributor

@rydmike From what I see, the scaffoldBackgroundColor is moved in a ScaffoldThemeData. Maybe that's a change after your recommendations. Anyways, thanks for keeping track of the ThemeData changes for all of us.

@rydmike
Copy link
Contributor

rydmike commented Nov 29, 2021

@talamaska Thanks, I noticed the addition as well. Perhaps it was a part of the plan all along. Probably so, since if it were not, it would result in new ThemeData that has no migration path for certain use cases.

@ghost
Copy link

ghost commented Feb 4, 2022

Currently, I am developing an app that should look Android'ish on Android and iOS'ish on iOS. So I use the MaterialApp for Android and the CupertinoApp for iOS. And I also try to get a Material- and CupertinoTheme together, both with dark and light colors. It isn't easy :(

I saw that CupertinoApp has only one theme parameter, and you use the CupertinoDynamicColor to define the light and dark colors (and some more).

Now I wonder why we don't have the same for the MaterialApp? Would it be a good idea to remove all these darkTheme, highContrastTheme, and highContrastDarkTheme from the MaterialApp and use a MaterialDynamicColor?

@rydmike
Copy link
Contributor

rydmike commented Feb 18, 2022

Additional colors to add to above list?

Should perhaps the following colors also be mentioned above among the ThemeData colors that should be deprecated/moved/removed?

  • primaryColorLight
  • primaryColorDark

They are currently not listed, but I doubt the intention is for them to remain. (cc @guidezpl)

primaryColorLight

A lighter color of primary. It is only used by CircleAvatar.
A potential replacement color is ColorScheme.primaryContainer.

primaryColorDark

A darker color of primary, it is used by CircleAvatar.
A potential replacement color is ColorScheme.onPrimaryContainer.

Challenges

The replacements would not be an exact match, so it would be breaking, but it matches the current design intent, if primaryContainer and onPrimaryContainer are using color tones as intended by M3 color design.

Status of primaryColorLight and pimaryColorDark

I wrote quite a bit about some past ThemeData color challenges here #65782. I was about to close the old issue, since most of the topics mentioned in it have been or are being addressed by the in progress ThemeData migration being tracked in this issue.

I did however not see anything addressing or mentioning primaryColorLight and primaryColorDark in ThemeData. Which does not mean it does not already exist, I might just have missed it.

The presence of primaryColorLight and primaryColorDark in ThemeData if kept, will continue to cause potential confusion.

Currently if you create a theme with ThemeData.from or just ThemeData and you give it a ColorScheme in colorScheme and don't provide a primarySwatch that would match in tones what you used for your primary in the ColorScheme, or directly give the color properties primaryColorLight and primaryColorDark values that fit your ColorScheme's primary color. Well, then you end up with primaryColorLight and primaryColorDark having default color values (blue hues, or grey in dark mode) that have nothing to do with whatever color you used in your ColorScheme as primary color, unless it happened to be a shade of blue close to the M2 blue swatch. Plus in the deprecate/move/remove list above, there is also this:

Deprecate primarySwatch from ThemeData factory constructor (8)

Which further complicates the continued existence of primaryColorLight and primaryColorDark in ThemeData.


EDIT Aug 3, 2022: Obviously primaryColor itself is also not mentioned in the ThemeData System Updates, should it also be included?

thejitenpatel pushed a commit to thejitenpatel/flutter that referenced this issue Sep 27, 2024
Reverts: flutter#155476
Initiated by: eyebrowsoffire
Reason for reverting: The newly added tests are failing in postsubmit. See https://ci.chromium.org/ui/p/flutter/builders/prod/Windows%20framework_tests_libraries/19062/overview
Original PR Author: QuncCccccc

Reviewed By: {TahaTesser}

This change reverts the following previous change:
This PR is to make preparations to make `TabBarTheme` conform to Flutter's conventions for component themes:

* Added a `TabBarThemeData` class which defines overrides for the defaults for `TabBar` properties.
* Added 2 `TabBarTheme` constructor parameters: `TabBarThemeData? data` and `Widget? child`. This is now the preferred way to configure a `TabBarTheme`:
```
TabBarTheme(
  data: TabBarThemeData(labelColor: xxx, indicatorColor: xxx, ...),
  child: TabBar(...)
)
```
  These two properties are made nullable to not break existing apps which has customized `ThemeData.tabBarTheme`.

* Changed the type of component theme defaults from `TabBarTheme` to `TabBarThemeData`.

TODO:

* Fix internal failures.
* Change the type of `ThemeData.tabBarTheme` from `TabBarTheme` to `TabBarThemeData`. This may cause breaking changes, a migration guide will be created.

Addresses the "theme normalization" sub project within flutter#91772
auto-submit bot pushed a commit that referenced this issue Oct 2, 2024
)

Following #153982, this PR is to normalize `ThemeData.dialogTheme`; change the `DialogTheme dialogTheme` property to `DialogThemeData dialogTheme` in ThemeData. In `ThemeData()` and `ThemeData.copyWith()`, the dialogTheme parameter type is changed to `Object?` to accept both `DialogTheme` and `DialogThemeData` so that we won't cause immediate breaking change and make sure rolling is smooth. Once all component themes are normalized, these `Object?` types should be changed to `xxxThemeData`.

There's no way to create a dart fix because we can't add a "@deprecated" label for `DialogTheme`; `DialogTheme` is a new `InheritedWidget` subclass now.

Addresses the "theme normalization" sub project within #91772
auto-submit bot pushed a commit that referenced this issue Oct 4, 2024
Following #151914, this PR is to normalize `ThemeData.cardTheme`; change the `CardTheme cardTheme` property to `CardThemeData cardTheme` in `ThemeData`. In `ThemeData()` and `ThemeData.copyWith()`, the `cardTheme` parameter type is changed to `Object?` to accept both `CardTheme` and `CardThemeData` so that we won't cause immediate breaking change and make sure rolling is smooth. Once all component themes are normalized, these `Object?` types should be changed to `xxxThemeData`.

There's no way to create a dart fix because we can't add a "@deprecated" label for `CardTheme` because `CardTheme` is a new InheritedWidget subclass now.

Addresses the "theme normalization" sub project within #91772
auto-submit bot pushed a commit that referenced this issue Oct 8, 2024
Following #155476, this PR is to normalize `ThemeData.tabBarTheme`; change the `TabBarTheme tabBarTheme` property to `TabBarThemeData tabBarTheme` in `ThemeData`. In `ThemeData()` and `ThemeData.copyWith()`, the `tabBarTheme` parameter type is changed to `Object?` to accept both `TabBarTheme` and `TabBarThemeData` so that we won't cause immediate breaking change and make sure rolling is smooth. Once all component themes are normalized, these `Object?` types should be changed to `xxxThemeData`.

There's no way to create a dart fix because we can't add a "@deprecated" label for TabBarTheme; TabBarTheme is a new InheritedWidget subclass now.

Addresses the "theme normalization" sub project within #91772
auto-submit bot pushed a commit that referenced this issue Oct 24, 2024
…ata.backgroundColor` (#155072)

Related to [�� Material Theme System Updates](#91772)
@rydmike
Copy link
Contributor

rydmike commented Oct 25, 2024

Deprecation of ThemeData.scaffoldBackgroundColor

I noticed that the mention of adding a ScaffoldThemeData with a background color and ThemeData.scaffoldTheme in relation to the deprecation of ThemeData.scaffoldBackgroundColor was removed in this edit:

Screenshot 2024-10-25 at 18 00 02

I would like to point out that not having a migration path for providing a custom color for the themed background color of the Scaffold, will severely break pretty much every app, well OK every 2nd app at least.

Deprecating the property is of course already breaking, but what is worse is that just removing it without providing a new themeable property for it, results in that there is no migration path. Since, if you just remove scaffoldBackgroundColor, it will be impossible to theme it like you can now. It will just get a default ColorScheme mapping (probably surface), but that does not help all with all the custom color assignments that exist today to ThemeData.scaffoldBackgroundColor.

Properties like e.g. ThemeData.dialogBackgroundColor do not have this problem, since the dialog background can still be themed to whatever desired color, in the dialog component theme, so deprecation of e.g. ThemeData.dialogBackgroundColor is of course breaking for many too, but it has a clear and simple migration path. The ThemeData.scaffoldBackgroundColor color needs this too.

Proposal

Either

  1. Do not deprecate ThemeData.scaffoldBackgroundColor

Or

  1. Deprecate it and also add a component theme for it, like originally mentioned.

Option 2 of course opens up opportunities for adding a few more themeable properties to existing Scaffold properties. Some of would be helpful to have there, like e.g. extendBody and extendBodyBehindAppBar to mention a few. Of course, to add them, the Scaffold bool properties will need to be made nullable and fallback via prop value to theme value and to defaults, but it would not break any current behavior.

@flutter-triage-bot
Copy link

This issue is assigned to @QuncCccccc but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!

@flutter-triage-bot flutter-triage-bot bot added the Bot is counting down the days until it unassigns the issue label Nov 3, 2024
@github-project-automation github-project-automation bot moved this to To do in Nevercode Dec 6, 2024
@TahaTesser TahaTesser moved this from To do to In progress in Nevercode Dec 9, 2024
@flutter-triage-bot flutter-triage-bot bot removed the Bot is counting down the days until it unassigns the issue label Dec 9, 2024
@flutter-triage-bot flutter-triage-bot bot added the Bot is counting down the days until it unassigns the issue label Dec 10, 2024
@flutter-triage-bot
Copy link

This issue is assigned to @QuncCccccc but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!

@flutter-triage-bot flutter-triage-bot bot removed the triaged-design Triaged by Design Languages team label Jan 10, 2025
@flutter-triage-bot
Copy link

This issue was assigned to @QuncCccccc but has had no status updates in a long time. To remove any ambiguity about whether the issue is being worked on, the assignee was removed.

@flutter-triage-bot flutter-triage-bot bot removed the Bot is counting down the days until it unassigns the issue label Jan 10, 2025
@Piinks Piinks added the triaged-design Triaged by Design Languages team label Jan 10, 2025
github-merge-queue bot pushed a commit that referenced this issue Jan 22, 2025
…icatorColor` (#160024)

Related to [☂️ Material Theme System
Updates](#91772)

## Pre-launch Checklist

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

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

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Wasmund1 pushed a commit to Wasmund1/flutter that referenced this issue Jan 24, 2025
…icatorColor` (flutter#160024)

Related to [☂️ Material Theme System
Updates](flutter#91772)

## Pre-launch Checklist

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

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

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
@TahaTesser TahaTesser moved this from In progress to To do in Nevercode Feb 21, 2025
github-merge-queue bot pushed a commit that referenced this issue May 13, 2025
## Description

While preparing a PR to normalize `InputDecorationTheme` (part of
#91772), I spotted some typos
in tab bar theme and dialog theme documentation:

## Tests

Documentation only
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: tech-debt Technical debt, code quality, testing, etc. f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. P2 Important issues not at the top of the work list team-design Owned by Design Languages team triaged-design Triaged by Design Languages team
Projects
Status: To do
Status: 🚧 In Progress
Development

No branches or pull requests

10 participants