Skip to content
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

SurfaceTintColor parameter added to control background color more clean #156

Merged
merged 2 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ class WoltModalSheetTopBar extends StatelessWidget {
final backgroundColor = page.backgroundColor ??
themeData?.backgroundColor ??
defaultThemeData.backgroundColor;
final surfaceTintColor =
themeData?.surfaceTintColor ?? defaultThemeData.surfaceTintColor;
final surfaceTintColor = page.surfaceTintColor ??
themeData?.surfaceTintColor ??
defaultThemeData.surfaceTintColor;

// Create the default top bar widget.
SizedBox topBarWidget = SizedBox(
Expand Down
29 changes: 29 additions & 0 deletions lib/src/modal_page/sliver_wolt_modal_sheet_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,34 @@ class SliverWoltModalSheetPage {
/// The background color of the page.
final Color? backgroundColor;

/// The color of the surface tint overlay applied to the material color
/// to indicate elevation for the modal sheet page. The [surfaceTintColor] is applied to the
/// modal sheet background color, top bar color, and the sticky action bar wrapper colors.
///
/// {@template flutter.material.material.surfaceTintColor}
/// Material Design 3 introduced a new way for some components to indicate
/// their elevation by using a surface tint color overlay on top of the
/// base material [color]. This overlay is painted with an opacity that is
/// related to the [elevation] of the material.
///
/// If [ThemeData.useMaterial3] is false, then this property is not used.
///
/// If [ThemeData.useMaterial3] is true and [surfaceTintColor] is not null and
/// not [Colors.transparent], then it will be used to overlay the base [backgroundColor]
/// with an opacity based on the [modalElevation].
///
/// If [ThemeData.useMaterial3] is true and [surfaceTintColor] is null, then the default
/// [surfaceTintColor] value is taken from the [ColorScheme].
///
/// See also:
///
/// * [ThemeData.useMaterial3], which turns this feature on.
/// * [ElevationOverlay.applySurfaceTint], which is used to implement the
/// tint.
/// * https://m3.material.io/styles/color/the-color-system/color-roles
/// which specifies how the overlay is applied.
final Color? surfaceTintColor;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the documentation I provided in the existing source code is wrong. Let's fix this here, and in the old place. Here is my suggestion:

  /// The color of the surface tint overlay applied to the material color
  /// to indicate elevation for the modal sheet page. The [surfaceTintColor] is applied to the 
  /// modal sheet background color, top bar color, and the sticky action bar wrapper colors.
  ///
  /// {@template flutter.material.material.surfaceTintColor}
  /// Material Design 3 introduced a new way for some components to indicate
  /// their elevation by using a surface tint color overlay on top of the
  /// base material [color]. This overlay is painted with an opacity that is
  /// related to the [elevation] of the material.
  ///
  /// If [ThemeData.useMaterial3] is false, then this property is not used.
  ///
  /// If [ThemeData.useMaterial3] is true and [surfaceTintColor] is not null and
  /// not [Colors.transparent], then it will be used to overlay the base [backgroundColor]
  /// with an opacity based on the [modalElevation].
  ///
  /// If [ThemeData.useMaterial3] is true and [surfaceTintColor] is null, then the default 
  /// [surfaceTintColor] value is taken from the [ColorScheme].
  ///
  /// See also:
  ///
  ///   * [ThemeData.useMaterial3], which turns this feature on.
  ///   * [ElevationOverlay.applySurfaceTint], which is used to implement the
  ///     tint.
  ///   * https://m3.material.io/styles/color/the-color-system/color-roles
  ///     which specifies how the overlay is applied.


/// Height of the navigation bar. This value will also be the height of the top bar.
///
/// The navigation bar layer has a transparent background, and sits directly above the top bar
Expand Down Expand Up @@ -182,6 +210,7 @@ class SliverWoltModalSheetPage {
this.heroImage,
this.heroImageHeight,
this.backgroundColor,
this.surfaceTintColor,
this.hasSabGradient,
this.enableDrag,
this.sabGradientColor,
Expand Down
3 changes: 3 additions & 0 deletions lib/src/modal_page/wolt_modal_sheet_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class WoltModalSheetPage extends SliverWoltModalSheetPage {
super.heroImage,
super.heroImageHeight,
super.backgroundColor,
super.surfaceTintColor,
super.hasSabGradient,
super.sabGradientColor,
super.enableDrag,
Expand All @@ -71,6 +72,7 @@ class WoltModalSheetPage extends SliverWoltModalSheetPage {
Widget? heroImage,
double? heroImageHeight,
Color? backgroundColor,
Color? surfaceTintColor,
bool? hasSabGradient,
Color? sabGradientColor,
bool? enableDrag,
Expand All @@ -91,6 +93,7 @@ class WoltModalSheetPage extends SliverWoltModalSheetPage {
heroImage: heroImage ?? this.heroImage,
heroImageHeight: heroImageHeight ?? this.heroImageHeight,
backgroundColor: backgroundColor ?? this.backgroundColor,
surfaceTintColor: surfaceTintColor ?? this.surfaceTintColor,
hasSabGradient: hasSabGradient ?? this.hasSabGradient,
sabGradientColor: sabGradientColor ?? this.sabGradientColor,
enableDrag: enableDrag ?? this.enableDrag,
Expand Down
37 changes: 29 additions & 8 deletions lib/src/theme/wolt_modal_sheet_default_theme_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,40 @@ class WoltModalSheetDefaultThemeData extends WoltModalSheetThemeData {
WoltModalSheetDefaultThemeData(this.context);

final BuildContext context;
late final ColorScheme _colors = Theme.of(context).colorScheme;
late final ColorScheme _colorsScheme = Theme.of(context).colorScheme;

/// Overrides the default value for surfaceTintColor.
/// The color of the surface tint overlay applied to the material color
/// to indicate elevation for the modal sheet page. The [surfaceTintColor] is applied to the
/// modal sheet background color, top bar color, and the sticky action bar wrapper colors.
///
/// If null, [WoltModalSheet] will not display an overlay color.
/// {@template flutter.material.material.surfaceTintColor}
/// Material Design 3 introduced a new way for some components to indicate
/// their elevation by using a surface tint color overlay on top of the
/// base material [color]. This overlay is painted with an opacity that is
/// related to the [elevation] of the material.
///
/// See [Material.surfaceTintColor] for more details.
/// If [ThemeData.useMaterial3] is false, then this property is not used.
///
/// If [ThemeData.useMaterial3] is true and [surfaceTintColor] is not null and
/// not [Colors.transparent], then it will be used to overlay the base [backgroundColor]
/// with an opacity based on the [modalElevation].
///
/// If [ThemeData.useMaterial3] is true and [surfaceTintColor] is null, then the default
/// [surfaceTintColor] value is taken from the [ColorScheme].
///
/// See also:
///
/// * [ThemeData.useMaterial3], which turns this feature on.
/// * [ElevationOverlay.applySurfaceTint], which is used to implement the
/// tint.
/// * https://m3.material.io/styles/color/the-color-system/color-roles
/// which specifies how the overlay is applied.
@override
Color get surfaceTintColor => _colors.surfaceTint;
Color get surfaceTintColor => _colorsScheme.surfaceTint;

/// The background color of the modal sheet.
@override
Color get backgroundColor => _colors.surface;
Color get backgroundColor => _colorsScheme.surface;

/// The elevation of the modal sheet.
@override
Expand Down Expand Up @@ -49,7 +70,7 @@ class WoltModalSheetDefaultThemeData extends WoltModalSheetThemeData {
bool get enableDrag => true;

@override
Color get dragHandleColor => _colors.onSurfaceVariant.withOpacity(0.4);
Color get dragHandleColor => _colorsScheme.onSurfaceVariant.withOpacity(0.4);

/// The size of the drag handle.
@override
Expand All @@ -61,7 +82,7 @@ class WoltModalSheetDefaultThemeData extends WoltModalSheetThemeData {

/// The elevation color of the modal bar.
@override
Color get topBarShadowColor => _colors.shadow;
Color get topBarShadowColor => _colorsScheme.shadow;

/// The elevation of the top bar.
@override
Expand Down
27 changes: 24 additions & 3 deletions lib/src/theme/wolt_modal_sheet_theme_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,32 @@ class WoltModalSheetThemeData extends ThemeExtension<WoltModalSheetThemeData> {
this.mainContentScrollPhysics,
});

/// Overrides the default value for surfaceTintColor.
/// The color of the surface tint overlay applied to the material color
/// to indicate elevation for the modal sheet page. The [surfaceTintColor] is applied to the
/// modal sheet background color, top bar color, and the sticky action bar wrapper colors.
///
/// If null, [WoltModalSheet] will not display an overlay color.
/// {@template flutter.material.material.surfaceTintColor}
/// Material Design 3 introduced a new way for some components to indicate
/// their elevation by using a surface tint color overlay on top of the
/// base material [color]. This overlay is painted with an opacity that is
/// related to the [elevation] of the material.
///
/// See [Material.surfaceTintColor] for more details.
/// If [ThemeData.useMaterial3] is false, then this property is not used.
///
/// If [ThemeData.useMaterial3] is true and [surfaceTintColor] is not null and
/// not [Colors.transparent], then it will be used to overlay the base [backgroundColor]
/// with an opacity based on the [modalElevation].
///
/// If [ThemeData.useMaterial3] is true and [surfaceTintColor] is null, then the default
/// [surfaceTintColor] value is taken from the [ColorScheme].
///
/// See also:
///
/// * [ThemeData.useMaterial3], which turns this feature on.
/// * [ElevationOverlay.applySurfaceTint], which is used to implement the
/// tint.
/// * https://m3.material.io/styles/color/the-color-system/color-roles
/// which specifies how the overlay is applied.
final Color? surfaceTintColor;

/// The background color of the modal sheet.
Expand Down
5 changes: 3 additions & 2 deletions lib/src/widgets/wolt_sticky_action_bar_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ class WoltStickyActionBarWrapper extends StatelessWidget {
final hasSabGradient = page.hasSabGradient ??
themeData?.hasSabGradient ??
defaultThemeData.hasSabGradient;
final surfaceTintColor =
themeData?.surfaceTintColor ?? defaultThemeData.surfaceTintColor;
final surfaceTintColor = page.surfaceTintColor ??
themeData?.surfaceTintColor ??
defaultThemeData.surfaceTintColor;
return Column(
children: [
// If a gradient is required, add a Container with a linear gradient decoration.
Expand Down
3 changes: 2 additions & 1 deletion lib/src/wolt_modal_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ class _WoltModalSheetState extends State<WoltModalSheet> {
defaultThemeData.maxDialogWidth;
final shadowColor =
themeData?.shadowColor ?? defaultThemeData.shadowColor;
final surfaceTintColor = themeData?.surfaceTintColor ??
final surfaceTintColor = page.surfaceTintColor ??
themeData?.surfaceTintColor ??
defaultThemeData.surfaceTintColor;
final modalElevation =
themeData?.modalElevation ?? defaultThemeData.modalElevation;
Expand Down