Skip to content

Conversation

@darrenaustin
Copy link
Contributor

As part of the Material 3 Migration, this PR adds support for the new surface tint overlay feature to the Material widget. If a new surfaceTintColor is provided to the Material widget it will apply this color to the base color with an opacity based on the elevation. This is described in detail in the Material 3 spec.

Surface Tint

In order to use this new feature you must opt-in with the useMaterial3 flag:

  return MaterialApp(
    theme: ThemeData(useMaterial3: true),
    // ...
  );

Then you can use the new surfaceTintColor to turn on an overlay for the given Material widget:

   Material(
     elevation: 6,
     surfaceTintColor: Theme.of(context).colorScheme.primary,
     shadowColor: Theme.of(context).colorScheme.shadow,
   );

This PR also changes the default value for Material.shadowColor when ThemeData.useMaterial3 is true. Previous to Material 3, if shadowColor was null it would default to ThemeData.shadowColor. For Material 3 in some situations we need to be able to turn off the drop shadow even if there is an elevation. Therefore if ThemeData.useMaterial3 is true and shadowColor is null then no drop shadow will be rendered.

Existing M2 tests were moved to their own group and new M3 tests were added.

Fixes: #91607

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. c: contributor-productivity Team-specific productivity, code health, technical debt. labels Mar 14, 2022
Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

In a future PR it would help to include an example that generated the illustration in this PR's description, along with a switch for dark/light mode.

@darrenaustin darrenaustin merged commit 6ec0b83 into flutter:master Mar 17, 2022
@darrenaustin darrenaustin deleted the m3_elevation_overlay branch March 17, 2022 22:58
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Mar 18, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 18, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Mar 18, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: contributor-productivity Team-specific productivity, code health, technical debt. f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update elevation overlay to apply in both light and dark theme

3 participants