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 ColorScheme where we use Brightness.light we get a correct dark dark shadow, typically black, since onBackground in 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.
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
ColorSchemetheshadowproperty by default returnsonBackgroundinColorSchemeof both schemes being of brightnesslightanddark.Link to master source:
flutter/packages/flutter/lib/src/material/color_scheme.dart
Line 711 in 4d9e6d9
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
ColorSchememadewith
Brightness.darkalso returns a dark, or evenColors.blackcolor by default, as itsshadowcolor.Actual results
We now get a light
ColorScheme.shadowcolor, most commonly a white shadow color in schemes withColorScheme.brightnessset toBrightness.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.
ThemeData factory
Using the
ThemeDatafactory, it always sets the current actually used shadow color to black, regardless of brightness, if not defined.Link to master source:
flutter/packages/flutter/lib/src/material/theme_data.dart
Line 454 in 4d9e6d9
This is correct and expected behavior.
ColorScheme.fromSeed
If we look a the new Material 3
ColorScheme.fromSeedit correctly assigns the neutral tone [0] from the seed generated tonal palette for both light and dark brightness toshadow. Thus it also always assigns completely black color from the seed generated tonal palette asshadowcolor in both dark and light brightness.This is correct and expected behavior.
Conclusion
At current stage the
ColorScheme.shadowis 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 ambientTheme.of(context).colorScheme.shadowin a dark theme in a custom widget. If you do, then you will see this wrong default shadow color behavior.Proposed Corrective Action
Change
ColorSchemeshadowgetter to:This produces the same default as current
ThemeDatafactory forshadowColorand will thus provideThemeData.colorScheme.shadowwith same legacy default when migrating SDK UI widgets to use it, instead ofThemeData.shadowColor. IfColorSchemedefault for the getter is not modified we will get white shadows in dark mode instead, which is probably not desired.