Skip to content

Use ColorScheme.scrim for modal barrier/scrim defaults - #190911

Closed
byshy wants to merge 5 commits into
flutter:mainfrom
byshy:fix-color-scheme-scrim-barriers
Closed

byshy wants to merge 5 commits into
flutter:mainfrom
byshy:fix-color-scheme-scrim-barriers

Conversation

@byshy

@byshy byshy commented Aug 11, 2026

Copy link
Copy Markdown

When modal barrier or drawer scrim colors are not set via an explicit parameter or component theme, fall back to ColorScheme.scrim with an opacity matching Colors.black54 instead of hardcoding Colors.black54.

This allows apps that customize ColorScheme.scrim to theme dialog, modal bottom sheet, and drawer scrims consistently, while preserving the default appearance for the standard black scrim token.

Fallback order remains:

  1. Explicit parameter (barrierColor / drawerScrimColor)
  2. Component theme (DialogTheme, BottomSheetTheme, DrawerTheme)
  3. Theme.of(context).colorScheme.scrim.withValues(alpha: Colors.black54.a)

Fixes #190824

Pre-launch 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.

Made with Cursor

…nd drawers. Update documentation to clarify fallback behavior for `modalBarrierColor`, `barrierColor`, and `scrimColor`, ensuring they utilize `ColorScheme.scrim` with an opacity matching `Colors.black54` when not explicitly set. Add tests to verify the correct application of these color settings in various scenarios.
@github-actions github-actions Bot added framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages labels Aug 11, 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 BottomSheet, Dialog, Drawer, and Scaffold to use ColorScheme.scrim with an opacity matching Colors.black54 as the default fallback color for modal barriers and scrims. The review feedback highlights that ModalBottomSheetRoute.barrierColor and DialogRoute bypass their respective theme configurations (BottomSheetThemeData and DialogTheme/ThemeData.dialogTheme) when falling back to ColorScheme.scrim, and suggests checking the theme configurations first.

Comment on lines +1111 to +1119
Color get barrierColor {
if (modalBarrierColor != null) {
return modalBarrierColor!;
}
if (navigator != null) {
return Theme.of(navigator!.context).colorScheme.scrim.withValues(alpha: Colors.black54.a);
}
return Colors.black54;
}

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.

high

In ModalBottomSheetRoute.barrierColor, if modalBarrierColor is null, the getter directly falls back to ColorScheme.scrim without checking BottomSheetThemeData.modalBarrierColor. This violates the fallback order documented in the class comments and causes direct usages of ModalBottomSheetRoute to ignore the bottom sheet theme's barrier color.

Please update the getter to check BottomSheetThemeData.modalBarrierColor first.

  @override
  Color get barrierColor {
    if (modalBarrierColor != null) {
      return modalBarrierColor!;
    }
    if (navigator != null) {
      final ThemeData theme = Theme.of(navigator!.context);
      return theme.bottomSheetTheme.modalBarrierColor ??
             theme.colorScheme.scrim.withValues(alpha: Colors.black54.a);
    }
    return Colors.black54;
  }
References
  1. Search for counter-examples: Identify scenarios or edge cases that the proposed code does not handle. If a counter-example is found, propose a test case to demonstrate the gap. (link)

Comment on lines +1838 to +1840
barrierColor:
barrierColor ??
Theme.of(context).colorScheme.scrim.withValues(alpha: Colors.black54.a),

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.

high

In DialogRoute, when barrierColor is null, it falls back directly to ColorScheme.scrim without checking DialogTheme.barrierColor or ThemeData.dialogTheme.barrierColor. This causes direct usages of DialogRoute to ignore the dialog theme's barrier color, which is inconsistent with showDialog.

Please update the fallback to check the dialog theme's barrier color first.

         barrierColor:
             barrierColor ??
             DialogTheme.of(context).barrierColor ??
             Theme.of(context).dialogTheme.barrierColor ??
             Theme.of(context).colorScheme.scrim.withValues(alpha: Colors.black54.a),
References
  1. Search for counter-examples: Identify scenarios or edge cases that the proposed code does not handle. If a counter-example is found, propose a test case to demonstrate the gap. (link)

byshy added 2 commits August 11, 2026 15:34
…`DialogRoute` to prioritize theme settings. Update documentation to clarify fallback behavior for `modalBarrierColor` and `barrierColor`. Add tests to ensure correct application of these color settings in both bottom sheets and dialogs.
@dkwingsmt
dkwingsmt requested review from Piinks and QuncCccccc August 12, 2026 18:11
@byshy

byshy commented Aug 17, 2026

Copy link
Copy Markdown
Author

Hi @Piinks @QuncCccccc, is there anything left to do from my side? is the PR ready for review?

@Piinks Piinks 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.

Hi @byshy! Thanks for contributing! This is a change that should be made in flutter/packages in the new material_ui package.
There are some helpful instructions on how to move the PR over in #188444
Let us know if you need any help. :)

@Piinks Piinks added the Decoupling: Port to flutter/packages This PR is ready to be ported to flutter/packages. We will provide instructions to do so. label Aug 17, 2026
@QuncCccccc

Copy link
Copy Markdown
Contributor

Hi @byshy! Thanks a lot for your contribution! Do you mind porting this PR to material_ui package? #188444 shows the instruction to port it over! Once we have an open PR there, we can proceed with the fix!

@byshy

byshy commented Sep 2, 2026

Copy link
Copy Markdown
Author

@QuncCccccc sure thing

@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.

Thank you! Once the port PR is ready, feel free to close this one:)!

@byshy

byshy commented Sep 4, 2026

Copy link
Copy Markdown
Author

Ported to flutter/packages as flutter/packages#12746.

Closing this one as requested, since Material changes now land in material_ui.

cc @QuncCccccc @Piinks

@byshy byshy closed this Sep 4, 2026
@byshy
byshy deleted the fix-color-scheme-scrim-barriers branch September 4, 2026 06:31
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Nov 18, 2026
…12746)

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](https://m3.material.io/styles/elevation/applying-elevation). 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](flutter/flutter#190911)
Work towards flutter/flutter#188444
Fixes flutter/flutter#190824

## Pre-Review Checklist

**Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). 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.

[^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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Decoupling: Port to flutter/packages This PR is ready to be ported to flutter/packages. We will provide instructions to do so. f: material design framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants