-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Add BottomSheetTheme to enable theming color, elevation, shape of BottomSheet #31318
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
efde8dd
Introduce BottomSheetTheme and shape support for bottom sheet
f72d328
Add bottom sheet theme to ThemeData. Use theme in bottom sheet build
f03d738
Expose color, elevation, shape to showModalBottomSheet helper
da9ee6b
Expose color, elevation, shape to showBottomSheet helper
9c5495e
Address PR feedback
75523f0
Merge master
7c3772c
Address PR feedback
4518a06
Address additional PR feedback
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
packages/flutter/lib/src/material/bottom_sheet_theme.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| // Copyright 2019 The Chromium Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'dart:ui' show lerpDouble; | ||
|
|
||
| import 'package:flutter/foundation.dart'; | ||
| import 'package:flutter/rendering.dart'; | ||
|
|
||
| /// Defines default property values for [BottomSheet]'s [Material]. | ||
| /// | ||
| /// Descendant widgets obtain the current [BottomSheetThemeData] object | ||
| /// using `Theme.of(context).bottomSheetTheme`. Instances of | ||
| /// [BottomSheetThemeData] can be customized with | ||
| /// [BottomSheetThemeData.copyWith]. | ||
| /// | ||
| /// Typically a [BottomSheetThemeData] is specified as part of the | ||
| /// overall [Theme] with [ThemeData.bottomSheetTheme]. | ||
| /// | ||
| /// All [BottomSheetThemeData] properties are `null` by default. | ||
| /// When null, the [BottomSheet] will provide its own defaults. | ||
| /// | ||
| /// See also: | ||
| /// | ||
| /// * [ThemeData], which describes the overall theme information for the | ||
| /// application. | ||
| class BottomSheetThemeData extends Diagnosticable { | ||
| /// Creates a theme that can be used for [ThemeData.bottomSheetTheme]. | ||
| const BottomSheetThemeData({ | ||
| this.backgroundColor, | ||
| this.elevation, | ||
| this.shape, | ||
| }); | ||
|
|
||
| /// Default value for [BottomSheet.backgroundColor]. | ||
| /// | ||
| /// If null, [BottomSheet] defaults to [Material]'s default. | ||
| final Color backgroundColor; | ||
|
|
||
| /// Default value for [BottomSheet.elevation]. | ||
| /// | ||
| /// {@macro flutter.material.material.elevation} | ||
| /// | ||
| /// If null, [BottomSheet] defaults to 0.0. | ||
| final double elevation; | ||
rami-a marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// Default value for [BottomSheet.shape]. | ||
| /// | ||
| /// If null, no overriding shape is specified for [BottomSheet], so the | ||
| /// [BottomSheet] is rectangular. | ||
| final ShapeBorder shape; | ||
|
|
||
| /// Creates a copy of this object with the given fields replaced with the | ||
| /// new values. | ||
| BottomSheetThemeData copyWith({ | ||
| Color backgroundColor, | ||
| double elevation, | ||
| ShapeBorder shape, | ||
| }) { | ||
| return BottomSheetThemeData( | ||
| backgroundColor: backgroundColor ?? this.backgroundColor, | ||
| elevation: elevation ?? this.elevation, | ||
| shape: shape ?? this.shape, | ||
| ); | ||
| } | ||
|
|
||
| /// Linearly interpolate between two bottom sheet themes. | ||
| /// | ||
| /// If both arguments are null then null is returned. | ||
| /// | ||
| /// {@macro dart.ui.shadow.lerp} | ||
| static BottomSheetThemeData lerp(BottomSheetThemeData a, BottomSheetThemeData b, double t) { | ||
| assert(t != null); | ||
| if (a == null && b == null) | ||
| return null; | ||
| return BottomSheetThemeData( | ||
| backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), | ||
| elevation: lerpDouble(a?.elevation, b?.elevation, t), | ||
| shape: ShapeBorder.lerp(a?.shape, b?.shape, t), | ||
| ); | ||
| } | ||
|
|
||
| @override | ||
| int get hashCode { | ||
| return hashValues( | ||
| backgroundColor, | ||
| elevation, | ||
| shape, | ||
| ); | ||
| } | ||
|
|
||
| @override | ||
| bool operator ==(Object other) { | ||
| if (identical(this, other)) | ||
| return true; | ||
| if (other.runtimeType != runtimeType) | ||
| return false; | ||
| final BottomSheetThemeData typedOther = other; | ||
| return typedOther.backgroundColor == backgroundColor | ||
| && typedOther.elevation == elevation | ||
| && typedOther.shape == shape; | ||
| } | ||
|
|
||
| @override | ||
| void debugFillProperties(DiagnosticPropertiesBuilder properties) { | ||
| super.debugFillProperties(properties); | ||
| properties.add(DiagnosticsProperty<Color>('backgroundColor', backgroundColor, defaultValue: null)); | ||
| properties.add(DiagnosticsProperty<double>('elevation', elevation, defaultValue: null)); | ||
| properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape, defaultValue: null)); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.