Support for elevation based dark theme overlay color in the Material widget#35560
Merged
darrenaustin merged 10 commits intoflutter:masterfrom Jul 16, 2019
darrenaustin:material_dark_elevation_overlay
Merged
Support for elevation based dark theme overlay color in the Material widget#35560darrenaustin merged 10 commits intoflutter:masterfrom darrenaustin:material_dark_elevation_overlay
darrenaustin merged 10 commits intoflutter:masterfrom
darrenaustin:material_dark_elevation_overlay
Conversation
… Also added a `darkThemeOverlay` boolean to turn it off in cases where it not wanted.
- Renamed Material.darkThemeOverlay -> Material.applyDarkThemeElevationOverlay - Added applyDarkThemeElevationOverlay to ThemeData - Modified Material to use the theme's overlay setting if none is provided to the widget. - Turned the overlay off by default
8 tasks
HansMuller
approved these changes
Jul 4, 2019
Contributor
HansMuller
left a comment
There was a problem hiding this comment.
LGTM, mostly just some comments about the docs.
- Removed applyDarkThemeElevationOverlay from Material as it is covered by ThemeData. - Updated documentation based on feedback. - Made just the overlay color animate to get around issues with OutlineButton.
Contributor
Author
D'oh. Old habits die hard. Thanks. |
- Only apply the overlays to Material widgets using the surface color. - Switched to using the elevation->opacity formula that Android is using. - Renamed applyDarkThemeElevationOverlay -> applyElevationOverlay. - No longer checking against ThemeData.brightness to dark as applyElevationOverlay should only be set to true on dark themes.
rami-a
approved these changes
Jul 15, 2019
| ), | ||
| child: buildMaterial(color: surfaceColor, elevation: 8.0)) | ||
| ); | ||
| final RenderPhysicalShape model = getShadow(tester); |
Contributor
There was a problem hiding this comment.
Is there a reason the helper function is called getShadow? I was a little confused by this
HansMuller
approved these changes
Jul 15, 2019
| // indicate the level of elevation. | ||
| Color _elevationOverlayColor(BuildContext context, Color background, double elevation) { | ||
| final ThemeData theme = Theme.of(context); | ||
| if (elevation > 0.0 && |
Contributor
There was a problem hiding this comment.
Conventional formatting for this would be one-line or:
if (elevation > 0.0 &&
theme.applyElevationOverlay &&
background == theme.colorScheme.surface) {
| ChipThemeData chipTheme, | ||
| TargetPlatform platform, | ||
| MaterialTapTargetSize materialTapTargetSize, | ||
| bool applyElevationOverlay, |
Contributor
There was a problem hiding this comment.
Maybe applyElevationOverlayColor?
| /// | ||
| /// Material drop shadows can be difficult to see in a dark theme, so the | ||
| /// elevation of a surface should be portrayed with an "overlay" in addition | ||
| /// to the shadow. As the elevation of the component increases, the bright |
Contributor
There was a problem hiding this comment.
the bright => the white
| /// Note: this setting is here to maintain backwards compatibility with | ||
| /// apps that were built before the Material Dark theme specification | ||
| /// was published. New apps should set this to [true] for dark themes | ||
| /// (where [brightness] is [Brightness.dark]. |
| /// | ||
| /// See also: | ||
| /// | ||
| /// * [Material.elevation], which effects how transparent the overlay is. |
Contributor
There was a problem hiding this comment.
the overlay => the white overlay
| /// See also: | ||
| /// | ||
| /// * [Material.elevation], which effects how transparent the overlay is. | ||
| /// * [Material.color], which if it matches [colorScheme.surface] an overlay |
Contributor
There was a problem hiding this comment.
- [Material.color], the white color overlay will only be applied of the material's color is [colorScheme.surface].
Contributor
Author
There was a problem hiding this comment.
Much clearer. Thx.
| ), | ||
| ) | ||
| ); | ||
| await tester |
- Minor formatting and doc changes - Renamed ThemeData.applyElevationOverlay -> ThemeData.applyElevationOverlayColor
johnsonmh
pushed a commit
to johnsonmh/flutter
that referenced
this pull request
Jul 30, 2019
…widget (flutter#35560) Added support for a semi-transparent white overlay color for `Material` widgets to indicate their elevation in a dart theme. A new `ThemeData.applyElevationOverlayColor` flag was added to control this behavior, which is off by default for backwards compatibility reasons.
This was referenced Sep 6, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In dark themes, drop shadows used to indicate elevation in Material apps can be difficult to see. To help with this, the Material Dark theme specification, adds a new semi-transparent overlay on surfaces to lighten them according to their elevation. This PR adds support for this feature.
If a
Materialwidget is in a theme where the newThemeData.applyElevationOverlayflag is turned on, and theMaterial.coloris the theme's surface color (i.e.ThemeData.colorScheme.surface), then a semi-transparent white will be composited over theMaterial.colorfor the background of the widget. The level of the transparency follows the values in the specification.By default this feature is turned off to maintain backwards compatibility with apps built before the Dark theme spec was published.
To turn it on for your app, you can adjust your dark themes to have
ThemeData.applyElevationOverlayset totrue.Related Issues
#35494 - A previous attempt at this PR.
Tests
I added a group of new tests in material_test.dart to exercise this feature.
Checklist
///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?