-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Description
Material ColorScheme Shadow Default Value Issue
This issue contains only code review feedback and does not need any sample, nor Flutter doctor output.
They are replaced with links to master source with the observed minor issue.
Steps to Reproduce
When you create a ColorScheme the shadow property by default returns onBackground in ColorScheme of both schemes being of brightness light and dark.
final Color? _shadow;
/// A color use to paint the drop shadows of elevated components.
Color get shadow => _shadow ?? onBackground;Link to master source:
| Color get shadow => _shadow ?? onBackground; |
Expected results
In order for there not to be a white or almost white shadow in dark theme modes, it would be expected that a ColorScheme made
with Brightness.dark also returns a dark, or even Colors.black color by default, as its shadow color.
Actual results
We now get a light ColorScheme.shadow color, most commonly a white shadow color in schemes with ColorScheme.brightness set to Brightness.dark.
This unexpected and incorrect behavior.
It is also not according Material 2 or Material 3 Design Guide for objects to cast white shadows in dark theme mode.
In a
ColorSchemewhere we useBrightness.lightwe get a correct dark dark shadow, typically black, sinceonBackgroundin light scheme is typically defined to be black by default. This is expected and correct default shadow behavior in light brightness.
ThemeData factory
Using the ThemeData factory, it always sets the current actually used shadow color to black, regardless of brightness, if not defined.
shadowColor ??= Colors.black;Link to master source:
| shadowColor ??= Colors.black; |
This is correct and expected behavior.
ColorScheme.fromSeed
If we look a the new Material 3 ColorScheme.fromSeed it correctly assigns the neutral tone [0] from the seed generated tonal palette for both light and dark brightness to shadow. Thus it also always assigns completely black color from the seed generated tonal palette as shadow color in both dark and light brightness.
This is correct and expected behavior.
Conclusion
At current stage the ColorScheme.shadow is not actually yet used by any built-in widgets in stable 2.10.1 nor in master , so the issue is not seen unless you try to use the color in ambient Theme.of(context).colorScheme.shadow in a dark theme in a custom widget. If you do, then you will see this wrong default shadow color behavior.
Proposed Corrective Action
Change ColorScheme shadow getter to:
Color get shadow => _shadow ?? Colors.black;This produces the same default as current ThemeData factory for shadowColor and will thus provide ThemeData.colorScheme.shadow with same legacy default when migrating SDK UI widgets to use it, instead of ThemeData.shadowColor. If ColorScheme default for the getter is not modified we will get white shadows in dark mode instead, which is probably not desired.