Repository navigation
Conversation
…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.
There was a problem hiding this comment.
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.
| 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; | ||
| } |
There was a problem hiding this comment.
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
- 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)
| barrierColor: | ||
| barrierColor ?? | ||
| Theme.of(context).colorScheme.scrim.withValues(alpha: Colors.black54.a), |
There was a problem hiding this comment.
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
- 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)
…`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.
|
Hi @Piinks @QuncCccccc, is there anything left to do from my side? is the PR ready for review? |
|
@QuncCccccc sure thing |
QuncCccccc
left a comment
There was a problem hiding this comment.
Thank you! Once the port PR is ready, feel free to close this one:)!
|
Ported to flutter/packages as flutter/packages#12746. Closing this one as requested, since Material changes now land in |
…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.
When modal barrier or drawer scrim colors are not set via an explicit parameter or component theme, fall back to
ColorScheme.scrimwith an opacity matchingColors.black54instead of hardcodingColors.black54.This allows apps that customize
ColorScheme.scrimto theme dialog, modal bottom sheet, and drawer scrims consistently, while preserving the default appearance for the standard black scrim token.Fallback order remains:
barrierColor/drawerScrimColor)DialogTheme,BottomSheetTheme,DrawerTheme)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-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.Made with Cursor