-
Notifications
You must be signed in to change notification settings - Fork 28.7k
ThemeData.brightness == ThemeData.colorScheme.brightness #56956
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
ThemeData.brightness == ThemeData.colorScheme.brightness #56956
Conversation
a60663e
to
366d868
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, LGTM. Some minor comments and questions below.
@@ -270,8 +269,8 @@ class ThemeData with Diagnosticable { | |||
BottomNavigationBarThemeData bottomNavigationBarTheme, | |||
bool fixTextFieldOutlineLabel, | |||
}) { | |||
brightness ??= Brightness.light; | |||
final bool isDark = brightness == Brightness.dark; | |||
final Brightness _brightness = brightness ?? colorScheme?.brightness ?? Brightness.light; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means the user could still specify a brightness
that doesn't match the given colorScheme.brightness
. Perhaps if they are both given and don't match we should throw an assertion? Or maybe have the colorScheme.brightness
take precedence as that is what the eventual value will be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did the opposite. If you specify both, then the brightness parameter replaces the ColorScheme's brightness. Developers occasionally specify a brightness value in local Theme overrides, to override the the "correct" value, in order to flip light/dark color choices.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, then maybe I am missing something because if I set the brightness here that is different from the colorScheme's when do you override the colorScheme's in this constructor? I see where this brightness is used in the constructor to set a bunch of stuff, but then the colorScheme's brightness will be used after that with the new getter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, you're right. It makes more sense to catch this (likely) error than to support it. I've added the assert and a test for it.
@@ -659,7 +655,7 @@ class ThemeData with Diagnosticable { | |||
/// this theme is localized using text geometry using [ThemeData.localize]. | |||
factory ThemeData.light() => ThemeData(brightness: Brightness.light); | |||
|
|||
/// A default dark theme with a teal accent color. | |||
/// A default dark theme with a teal secondary [ColorScheme] color. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe more explicit here?
/// A default dark theme with a teal secondary [ColorScheme] color. | |
/// A default dark theme with a teal [ColorScheme.secondary] color. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -1054,6 +1045,8 @@ class ThemeData with Diagnosticable { | |||
final bool fixTextFieldOutlineLabel; | |||
|
|||
/// Creates a copy of this theme but with the given fields replaced with the new values. | |||
/// | |||
/// The [brightness] value is applied to the [colorScheme]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a little odd. When would you want to change the brightness of the colorScheme without changing its colors as well? Is this because we don't want to break the existing API by removing the brightness param here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I found one use-case in an internal app so I'm assuming that there are others in outside apps.
I think this is comparable to allowing the ThemeData brightness constructor parameter override the color scheme's brightness.
@@ -216,7 +216,6 @@ void main() { | |||
); | |||
|
|||
final ThemeData theme = ThemeData.raw( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a test to check that the brightness is set correctly with the changes to the constructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point; I will add that.
df560c7
to
b1c759d
Compare
That looks great. Thanks for doing this. |
The overall Material Theme should have one brightness value which indicates if the theme represents a light (default) or dark color scheme per https://material.io/design/color/dark-theme.html.
The ThemeData.brightness and ThemeData.colorScheme.brightness properties are redundant and currently they are not kept in sync. We are evolving the Theme's colorScheme as the primary source of default material components colors as well the overall theme's brightness.
This PR changes ThemeData.brightness to be a simple getter that returns
colorScheme.brightness
. It's part of the changes recommended in "Compute brightness, primaryColorBrightness, accentColorBrightness" section of flutter.dev/go/material-theme-system-updates.