Skip to content

[material_ui] Use ColorScheme.scrim for modal barrier/scrim defaults - #12746

Merged
auto-submit[bot] merged 24 commits into
flutter:mainfrom
byshy:fix-color-scheme-scrim-barriers
Nov 18, 2026
Merged

auto-submit[bot] merged 24 commits into
flutter:mainfrom
byshy:fix-color-scheme-scrim-barriers

Conversation

@byshy

@byshy byshy commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

When modal barrier or drawer scrim colors are not set via an explicit parameter or component theme, fall back to a default based on ColorScheme.scrim:

  • Material 3: ColorScheme.scrim at 32% opacity, per the Material 3 elevation spec. This changes the default M3 scrim opacity from 54% to 32%.
  • Material 2: Colors.black54 (unchanged).

The Material 3 defaults are added through the gen_defaults templates (dialog_template.dart, bottom_sheet_template.dart, drawer_template.dart) and regenerated into lib/src/generated/*_defaults_m3.g.dart as barrierColor, modalBarrierColor and scrimColor.

Fallback order:

  1. Explicit parameter (barrierColor / drawerScrimColor / scrimColor)
  2. Component theme (DialogThemeData.barrierColor, BottomSheetThemeData.modalBarrierColor, DrawerThemeData.scrimColor)
  3. The Material 3 / Material 2 default above

The default is resolved in showDialog, showModalBottomSheet and DrawerController. DialogRoute and ModalBottomSheetRoute are unchanged; showDialog and showModalBottomSheet already pass the resolved color to the route.

Ports #190911
Work towards flutter/flutter#188444
Fixes flutter/flutter#190824

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2

Enhance the handling of modal barrier colors in bottom sheets, dialogs, and drawers to utilize ColorScheme.scrim with an opacity matching Colors.black54 when no specific color is provided. This change ensures a consistent appearance across components and allows for better theme integration. Additionally, tests have been added to verify the new behavior and precedence rules for barrier colors.
@github-actions github-actions Bot added p: material_ui triage-design Should be looked at in design triage labels Sep 4, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the default fallback colors for dialog, modal bottom sheet, and drawer barriers/scrims to use ColorScheme.scrim with an opacity matching Colors.black54 when no explicit color or theme-specific color is provided. It also updates the corresponding documentation, adds a pending changelog entry, and introduces comprehensive widget tests to verify the new fallback behavior and precedence rules. There are no review comments, so I have no feedback to provide.

@shaakunuigurumi

shaakunuigurumi commented Sep 14, 2026 •

Copy link
Copy Markdown

I'm not sure whether this is better fit for a new issue but: Material 3 docs indicate that 54% black is not up to date anymore and to use 32% opacity instead. Directly using the alpha value of Colors.black54 and mixing it with the Material 3 scrim color is more of a refactor carrying on the ghost of Material 2 rather than going full-in. This asks the question whether a useMaterial3 flag is required here or whether this can be a "breaking" change.

See: https://m3.material.io/styles/elevation/applying-elevation.

@byshy

byshy commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

@shaakunuigurumi I'm fine with either approach, but I went with this since it was the reported issue, if the material 3 approach is the one to go with then I can do it once a decision is made 🙏

@byshy

byshy commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Hi @QuncCccccc @elliette, any updates on this PR?

@QuncCccccc QuncCccccc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The Material 3 specification already defines the scrim color role at 32% opacity. Could this PR use ColorScheme.scrim at 32% when useMaterial3 is true, while preserving Colors.black54 for Material 2? The current implementation combines the M3 color role with the existing M2 opacity and applies it to both modes.

@byshy

byshy commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

Sure thing, will handle that and update the PR ASAP @QuncCccccc

@byshy
byshy marked this pull request as draft September 22, 2026 06:40
….fallbackScrimColor. This change ensures consistent fallback behavior across dialogs, bottom sheets, and drawers, aligning with Material 3 specifications. Tests have been updated to reflect this new behavior.
…pha: 0.32)` for consistency with Material 3 specifications. Updated tests to reflect this change and removed unnecessary documentation imports.
@byshy
byshy marked this pull request as ready for review September 22, 2026 07:18
@byshy
byshy requested a review from QuncCccccc September 22, 2026 07:20

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces 'ThemeData.fallbackScrimColor' to serve as the default fallback color for modal barriers and drawer scrims when no explicit color or component theme color is provided. In Material 3, this defaults to 'ColorScheme.scrim' at 32% opacity, while in Material 2 it defaults to 'Colors.black54'. The fallback logic has been integrated into bottom sheets, dialogs, drawers, and scaffolds, and corresponding tests have been updated or added to verify this behavior. There are no review comments, so I have no feedback to provide.

@QuncCccccc QuncCccccc added the CICD Run CI/CD label Sep 30, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Oct 2, 2026
///
/// * [ColorScheme.scrim], which is used when [useMaterial3] is true.
/// * <https://m3.material.io/styles/elevation/applying-elevation>
Color get fallbackScrimColor {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the update! The M3/M2 values look right to me, but I'd prefer not to add this to ThemeData. The ThemeData.colorScheme is the preferred way to configure colors, and the other Color properties on ThemeData are being phased out. See the docs on ThemeData.colorScheme and the comment in the ThemeData factory that links to flutter/flutter#91772. For example, dialogBackgroundColor and indicatorColor were deprecated in favor of DialogThemeData.backgroundColor and TabBarThemeData.indicatorColor. Even as a read-only getter, fallbackScrimColor would be public API that we'd have to keep or deprecate later. Apps can already customize these colors with DialogThemeData.barrierColor, BottomSheetThemeData.modalBarrierColor and DrawerThemeData.scrimColor.

Could we remove fallbackScrimColor and compute the default from ColorScheme.scrim where it's needed (showDialog, showModalBottomSheet and DrawerController)? For example:

final ThemeData theme = Theme.of(context);
final Color defaultScrimColor = theme.useMaterial3
    ? theme.colorScheme.scrim.withValues(alpha: 0.32)
    : Colors.black54;

Repeating this in those three places is fine; we'd rather have that than new public API. The docs that point to ThemeData.fallbackScrimColor could then state the default directly ("ColorScheme.scrim at 32% opacity in Material 3, Colors.black54 in Material 2"). The tests that compare against the getter could assert the expected colors instead. What do you think?

@QuncCccccc QuncCccccc added the CICD Run CI/CD label Oct 2, 2026

@elliette elliette left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for sticking with this PR! Left a few small nits.

Also it looks like the PR description is now outdated, could you edit it to remove the reference to the ThemeData.fallbackScrimColor getter which was removed? Thanks!

@elliette elliette added the CICD Run CI/CD label Nov 6, 2026
@byshy

byshy commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

@elliette thanks for the review, will handle all points shortly

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 7, 2026
@byshy
byshy requested a review from elliette November 7, 2026 07:59
@elliette elliette added the CICD Run CI/CD label Nov 11, 2026
elliette
elliette previously approved these changes Nov 11, 2026

@elliette elliette left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Changes LGTM, thank you!

QuncCccccc
QuncCccccc previously approved these changes Nov 13, 2026

@QuncCccccc QuncCccccc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks so much for fixing the M3 default issue! This looks really good! LGTM with one comment that is requesting to change the version type.

@QuncCccccc QuncCccccc added the waiting for response The Flutter team cannot make further progress on this PR until the author responds label Nov 13, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 13, 2026
@byshy

byshy commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @elliette @QuncCccccc for approving the PR, excited to see it merged soon

@QuncCccccc I have fixed the latest comment 🌟

@github-actions github-actions Bot removed the waiting for response The Flutter team cannot make further progress on this PR until the author responds label Nov 13, 2026
@byshy
byshy dismissed stale reviews from QuncCccccc and elliette via 4aad075 November 16, 2026 21:11
@byshy
byshy requested review from QuncCccccc and elliette November 17, 2026 10:23
@elliette elliette added the CICD Run CI/CD label Nov 17, 2026
@github-actions github-actions Bot added the P2 Important issues not at the top of the work list label Nov 17, 2026

@QuncCccccc QuncCccccc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Thank you!

@QuncCccccc QuncCccccc added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 18, 2026
@auto-submit
auto-submit Bot merged commit c18e1b2 into flutter:main Nov 18, 2026
14 checks passed
vashworth pushed a commit to vashworth/flutter that referenced this pull request Nov 18, 2026
…r#196892)

flutter/packages@9af69be...dca2e58

2026-11-18 katelovett@google.com [ci] update workflow permissions
(flutter/packages#13696)
2026-11-18 mmohankrishna@google.com [material_ui] Fix DataTable row
hover flicker between cells (flutter/packages#13523)
2026-11-18 qazws78941@gmail.com [material_ui, cupertino_ui] Unify
localization generation instructions (flutter/packages#13109)
2026-11-18 33957976+byshy@users.noreply.github.com [material_ui] Use
ColorScheme.scrim for modal barrier/scrim defaults
(flutter/packages#12746)
2026-11-17 tarrinneal@gmail.com [pigeon] Stop silently skipping JNIgen
when env vars are unset and surface clear errors
(flutter/packages#13630)
2026-11-17 mdebbar@google.com [material_ui] Re-enable non-Wasm web unit
tests (flutter/packages#13671)
2026-11-17 53801679+ChandraChaan@users.noreply.github.com
[camera_platform_interface] Fix VideoRecordedEvent equality and hashCode
(flutter/packages#13452)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD p: material_ui P2 Important issues not at the top of the work list triage-design Should be looked at in design triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Material] Hardcoded Colors.black54 used for scrims/barriers instead of ColorScheme.scrim

4 participants