Repository navigation
[material_ui] Use ColorScheme.scrim for modal barrier/scrim defaults - #12746
Conversation
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.
There was a problem hiding this comment.
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.
|
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 See: https://m3.material.io/styles/elevation/applying-elevation. |
|
@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 🙏 |
|
Hi @QuncCccccc @elliette, any updates on this PR? |
QuncCccccc
left a comment
There was a problem hiding this comment.
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.
|
Sure thing, will handle that and update the PR ASAP @QuncCccccc |
….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.
There was a problem hiding this comment.
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.
| /// | ||
| /// * [ColorScheme.scrim], which is used when [useMaterial3] is true. | ||
| /// * <https://m3.material.io/styles/elevation/applying-elevation> | ||
| Color get fallbackScrimColor { |
There was a problem hiding this comment.
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?
elliette
left a comment
There was a problem hiding this comment.
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 thanks for the review, will handle all points shortly |
…nd scaffold files
QuncCccccc
left a comment
There was a problem hiding this comment.
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.
|
Thanks @elliette @QuncCccccc for approving the PR, excited to see it merged soon @QuncCccccc I have fixed the latest comment 🌟 |
…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
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:ColorScheme.scrimat 32% opacity, per the Material 3 elevation spec. This changes the default M3 scrim opacity from 54% to 32%.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 intolib/src/generated/*_defaults_m3.g.dartasbarrierColor,modalBarrierColorandscrimColor.Fallback order:
barrierColor/drawerScrimColor/scrimColor)DialogThemeData.barrierColor,BottomSheetThemeData.modalBarrierColor,DrawerThemeData.scrimColor)The default is resolved in
showDialog,showModalBottomSheetandDrawerController.DialogRouteandModalBottomSheetRouteare unchanged;showDialogandshowModalBottomSheetalready pass the resolved color to the route.Ports #190911
Work towards flutter/flutter#188444
Fixes flutter/flutter#190824
Pre-Review Checklist
[shared_preferences]///).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-assistbot 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
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