-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
ColorScheme Theme Quality Issues - Gaps in completeness and inconsistencies #65782
Comments
Hi @rydmike Thank you |
Hi Pedro @pedromassango, sure will do, and you are right the presentation of the issue could be clearer and the sample could explain it better as well. I will update both to do so. I'll drop you another tag when done, might not be until tomorrow. Ultimately parts of this quality issue/topic is also a bit of a matter of taste/opinion, but since the ColorScheme based theming is supposed to make creation of Material themes easier in Flutter, it would be nice if it did so in a more complete way when it comes to all properties in the resulting ThemeData. The way it is now there are too many remnants from the defaults Theme() factory. This leads to that when you make themes with Theme.from(colorScheme) you end up with a lot of color properties in the resulting ThemeData that has nothing to do with the ColorScheme you defined, some of which even affect defaults for some widgets. At last I think this is bit inconsistent and could be confusing to newcomers. The ColorScheme and Theme.from(colorScheme) are a later addition to Flutter, than the Theme() factory that grew way too big. They are a nice addition, but they behave a bit like the afterthought they are, thus reducing their usefulness a bit. Personally I like the ColorScheme based theming, but due to the gaps it has, we ended up just making our own variant of it that addresses the inconsistencies and gaps, my thinking around this issue is just that it would be nice if you would not have to do that. |
@pedromassangocode I updated the issue description to show the actual result and the expected result for both dark and light theme modes for the found ColorScheme resulting ThemeData gaps and inconsistencies. The sample code was also updated to state actual Result and Expected result and if it is OK or FAILED for both light and dark theme modes. The updated sample has the same URL as before and can be run in DartPad here: If the plan is to fully deprecate the direct ThemeData properties:
And eventually totally remove them from ThemeData(), then the gaps are perhaps more understandable, but even so, while waiting for that, they could and should imo have useful and matching color values when creating themes from ColorSchemes. |
Reproducible with latest flutter doctor -v
|
Thanks for the comprehensive report. As you may know, we're in the process of updating the theme system per https://flutter.dev/go/material-theme-system-updates. @darrenaustin - can you provide an update about where we are with flutter.dev/go/text-selection-theme? |
Yes, thanks for the report. As Hans mentioned we are working to transition everything over to ColorScheme based colors. We obviously have a ways to go. Currently we are in the process of migrating the text selection colors, which is described in the design doc. The first step landed with: #62014. This introduced the new After this transition all of these colors will be based off of colors from the |
Thanks @HansMuller for the link to the design doc, and yes I do recall reading it before, just had another read, lgtm. 👍 @darrenaustin The improvements will certainly be welcome, looking forward to them! 😃 The reason why I actually brought this up was to shed a bit light on that the current situation can be a bit confusing to newcomers if they try to use
Maybe the most obvious issue users will run into is the The properties I did notice, and also mentioned in the above report, that the new One small inconvenience issue with it is that when you create the The opt-in case on These are as I mentioned from the start all solvable minor issues that can dealt with, but they might be a bit confusing to someones who has not spent a lot of time getting to know the large and a bit messy ThemeData class and related classes. Totally understand that you are working on cleaning it up and looking forward to the results. We solved our ColorScheme backwards compatibility issues for now by making our own version of ColorScheme, well actually own version of the Theme.from(colorScheme) factory, that also sets the above ThemeData properties from colors in the ColorScheme in a fashion that addresses the gaps listed in this report, some values are computed based on values in the ColorScheme, since there are no appropriate values for it in the ColorScheme. This concerns I was just thinking that perhaps there is something that could be done within the framework to ease and support the migration towards using ColorScheme based theming as well? Eventually, if/when the '21 grab-bag properties' mentioned in the "Flutter Material Theme System Update" document are fully deprecated and removed from ThemeData, we will have to make a bit deeper updates in apps. Not a big issue and relatively easy to do. Regarding such a transition and eventually removing these properties, it is perhaps good to recognize that there probably are a lot of apps out there that uses custom/composed Widgets that just depend on properties from ThemeData for some of their styling. It is a common practical and pragmatic way to do things when you start with Flutter. We no longer do this for obvious reasons. For more robust and really re-usable custom Widgets we create our own themes, which we based on how the newer sub-themes in ThemeData were made for Flutter SDK Widgets. Obviously this only makes sense for more elaborate custom Widgets that might be used as internal packages or even published on pub.dev. |
Issue description
ColorScheme based themes create ThemeData that is inconsistent with the provided ColorScheme. Some sub themes are also incomplete when using ColorScheme based themes because
Theme.from(colorScheme)
does not set all Theme() color properties used by sub themes.For broader adoption of ColorScheme based theming, it would be useful if it behaved as might be expected and did not leave remnants of the default colors from Theme() factory in the resulting theme from a Theme.from(colorScheme) factory, where one would expect there should be colors from the colorScheme in use.
This issue demo uses
ColorScheme.light()
andColorScheme.dark()
andTheme.from(colorscheme)
for each of them to demonstrate incompleteness and inconsistencies in the resulting light and dark themes and to show that many Theme() color properties do not get any colors from the used ColorScheme applied. This makes the resulting ThemeData inconsistent with the ColorScheme used to create the ThemeData. In some cases this also affects default colors on some widgets, making the situation potentially even more confusing.Since the issue can easily be remedied with additional manual custom theming e.g. with
copyWith
, after creating a ColorScheme based theme withTheme.from(colorScheme)
, it is not a big issue, but the current situation does seem like an oversight and the incomplete and conflicting results may be confusing to new developers.It would be useful and more elegant if when using ColorScheme and Theme.from(colorScheme) it created more complete matching ThemeData results, were none of its color properties were left with Theme() factory defaults that potentially conflict with the used ColorScheme and also that no widgets were left with default colors that do not match the ColorScheme used to create ThemeData from ColorScheme.
Steps to Reproduce
This issue applies to all current Flutter versions and all channels.
The source code for the issue demo can be found here:
https://gist.github.com/rydmike/b59cea071eefdbe7c1332b2d014bc156
And the issues can easily be demonstrated and tried with this DartPad:
https://www.dartpad.dev/b59cea071eefdbe7c1332b2d014bc156
Results and description of gaps and issues with ColorScheme based themes
toggleableActiveColor
ColorScheme based themes will get the default dark theme based toggleable color and not the secondary color from the dark
ColorScheme. The resulting color may or may not fit with the used colors in ColorScheme based theme. The default dark theme color is close to ColorScheme.dark() so it works fairly well for the default values, but not for general usage.
Proposed fix:
ThemeData.from() should also set:
toggleableActiveColor: colorScheme.secondary
for better backwards compatibility and so that the dark mode toggleableActiveColor also matches the ColorScheme based theme in dark mode and not only light mode.
primaryColorDark
ColorScheme based themes do not set any color at all for the Theme() color primaryColorDark. It only gets default value from default Theme factory for both light and dark mode. The resulting color may or may not fit with the used colors in ColorScheme based theme.
Proposed fix:
For a better fit with legacy themes and to match the colors in the ColorScheme the ThemeData.from() should set primaryColorDark to a slightly darker hue based on colorScheme.primary for light themes.
primaryColorLight
ColorScheme based themes do not set any color at all for the Theme() color primaryColorLight. It only gets default value from default Theme factory for both light and dark mode. The resulting color may or may not fit with the used colors in ColorScheme based theme.
Proposed fix:
For a better fit with legacy themes and to match the colors in the ColorScheme the ThemeData.from() should set primaryColorLight to a lighter hue based on colorScheme.primary for light themes.
secondaryHeaderColor
ColorScheme based themes do not set any color at all for the Theme() color secondaryHeaderColor. It only gets default value from default Theme factory for both light and dark mode. The resulting color may or may not fit with the used colors in ColorScheme based theme.
Proposed fix:
For a better fit with legacy themes and to match the colors in the ColorScheme the ThemeData.from() should set secondaryHeaderColor to a much lighter hue based on colorScheme.primary for light themes.
Text selection when using ColorScheme based themes
The new "TextSelectionThemeData" and "useTextSelectionTheme" address the issues below, but only when used in
TextField()
andSelectableText()
. Still the color properties in the resulting ThemeData are left at their default values, which may be confusing and they also do not match the applied ColorScheme based theme.The
useTextSelectionTheme
cannot be set with ColorScheme directly, an extra copyWith (inconvenient) is required and even then the ThemeData result values are left at their Theme() defaults, this may be confusing as they do not match the applied ColorScheme colors.textSelectionColor
ColorScheme based themes do not set any color at all for the Theme() color textSelectionColor. It only gets default value from default Theme factory for both light and dark mode. The resulting color may or may not fit with the used colors in ColorScheme based theme.
Proposed fix:
For a better fit with legacy themes and to match the colors in the ColorScheme the ThemeData.from() should set textSelectionColor to a lighter hue based on colorScheme.primary for light themes and to colorScheme.secondary for dark themes.
Alternatively:
ColorScheme based themes could set the Theme() property to the colorScheme.primary based colors introduced with TextSelectionThemeData, this would not break older Theme() based themes and would make the property correctly ColorScheme based for themes based on ColorScheme.
textSelectionHandleColor
ColorScheme based themes do not set any color at all for the Theme() color textSelectionHandleColor. It only gets default value from default Theme factory for both light and dark mode. The resulting color may or may not fit with the used colors in ColorScheme based theme.
Proposed fix:
For a better fit with legacy themes and to match the colors in the ColorScheme the ThemeData.from() should set textSelectionHandleColor to a lighter hue based on colorScheme.primary for light themes and to a darker hue of colorScheme.secondary for dark themes.
Alternatively:
ColorScheme based themes could set the Theme() property to the colorScheme.primary based colors introduced with TextSelectionThemeData, this would not break older Theme() based themes and would make the property correctly ColorScheme based for themes based on ColorScheme and it would match the TextSelectionThemeData defaults.
cursorColor
ColorScheme based themes do not set any color at all for the Theme() color cursorColor. It only gets default value from default Theme factory for both light and dark mode. The resulting color may or may not fit with the used colors in ColorScheme based theme.
Proposed fix:
For a better fit with legacy themes and to match the colors in the ColorScheme the ThemeData.from() should set cursorColor to colorScheme.primary or some hue of it.
Alternatively:
ColorScheme based themes could set the Theme() property to the colorScheme.primary based colors introduced with TextSelectionThemeData, this would not break older Theme() based themes and would make the property correctly ColorScheme based for themes based on ColorScheme and it would match the TextSelectionThemeData defaults.
Note:
It is worth noticing that default Theme() uses the same fixed blue color for light and dark mode and that this blue color is not any variant of the default blue colors used in the default blue primary swatch, which is a bit odd. It is very close to the default blue hues in default Theme() and thus works well with the the default Theme(), but it does not work well with ColorScheme themes or any other none default and none blue based theme.
Flutter doctor
The text was updated successfully, but these errors were encountered: