New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow independent theming of Persistent and Modal bottom sheets Background Color #39333
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!!!
/// Value for [BottomSheet.backgroundColor] when the Bottom sheet is presented | ||
/// as a modal bottom sheet. | ||
/// | ||
/// If null, [BottomSheet.backgroundColor] defaults to [backgroundColor]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The defaulting rules for modal bottom sheets shouldn't be documented here. And line 464 in bottom_sheet.dart doesn't default to the theme's backgroundColor when modalBackgroundColor is null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -141,12 +141,16 @@ void main() { | |||
expect(material.clipBehavior, clipBehavior); | |||
}); | |||
|
|||
testWidgets('BottomSheetThemeData.modalElevation takes priority over BottomSheetThemeData.elevation for modal bottom sheets', (WidgetTester tester) async { | |||
testWidgets('Modal bottom sheet-specific parameters take priority over general bottom sheet parameters for modal bottom sheets', (WidgetTester tester) async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the title is accurate then we should be verifying that a modal bottom sheet's background and elevation are defined by the bottom sheet theme's background and elevation properties when modalElevation and modalBackgroundColor are null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -461,7 +461,7 @@ Future<T> showModalBottomSheet<T>({ | |||
theme: Theme.of(context, shadowThemeOnly: true), | |||
isScrollControlled: isScrollControlled, | |||
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel, | |||
backgroundColor: backgroundColor, | |||
backgroundColor: backgroundColor ?? Theme.of(context).bottomSheetTheme.modalBackgroundColor, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be:
backgroundColor ?? Theme.of(context).bottomSheetTheme.modalBackgroundColor ?? Theme.of(context).bottomSheetTheme.backgroundColor;
It would be best to allow Theme.of(context).bottomSheetTheme
to be null and to cache the value, so:
final BottomSheetThemeData theme = Theme.of(context).bottomSheetTheme;
backgroundColor: backgroundColor ?? theme?.modalBackgroundColor ?? theme?.backgroundColor;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This good however it looks like showBottomSheet doesn't document the elevation or color parameters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -427,6 +427,10 @@ class _ModalBottomSheetRoute<T> extends PopupRoute<T> { | |||
/// that a modal [BottomSheet] needs to be displayed above all other content | |||
/// but the caller is inside another [Navigator]. | |||
/// | |||
/// The optional [backgroundColor], [elevation], [shape], and [clipBehavior] | |||
/// parameters can be passed in to customize the appearance and behavior of | |||
/// persistent bottom sheets. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're referring to modal bottom sheets here
Description
BottomSheetThemeData has an additional field modalBackgroundColor which makes it possible to set different background colors between persistent and modal bottom sheets.
Tests
I added the following tests:
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze --flutter-repo
) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?