-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwolt_modal_sheet_theme_data.dart
276 lines (243 loc) · 10.9 KB
/
wolt_modal_sheet_theme_data.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:wolt_modal_sheet/src/theme/wolt_modal_sheet_animation_style.dart';
import 'package:wolt_modal_sheet/src/wolt_modal_sheet.dart';
@immutable
class WoltModalSheetThemeData extends ThemeExtension<WoltModalSheetThemeData> {
const WoltModalSheetThemeData({
this.backgroundColor,
this.modalElevation,
this.modalBarrierColor,
this.bottomSheetShape,
this.dialogShape,
this.showDragHandle,
this.dragHandleColor,
this.dragHandleSize,
this.enableDrag,
this.topBarShadowColor,
this.topBarElevation,
this.heroImageHeight,
this.hasSabGradient,
this.sabGradientHeight,
this.sabGradientColor,
this.navBarHeight,
this.hasTopBarLayer,
this.isTopBarLayerAlwaysVisible,
this.minDialogWidth,
this.maxDialogWidth,
this.minPageHeight,
this.maxPageHeight,
this.surfaceTintColor,
this.clipBehavior,
this.shadowColor,
this.mainContentScrollPhysics,
this.animationStyle,
this.resizeToAvoidBottomInset,
});
/// 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;
/// The background color of the modal sheet.
final Color? backgroundColor;
/// The elevation of the modal sheet.
final double? modalElevation;
/// The color of the modal barrier.
final Color? modalBarrierColor;
/// The shape of the bottom sheet.
final ShapeBorder? bottomSheetShape;
/// The shape of the dialog.
final ShapeBorder? dialogShape;
/// Whether to show the drag handle.
final bool? showDragHandle;
/// The color of the drag handle.
final Color? dragHandleColor;
/// The size of the drag handle.
final Size? dragHandleSize;
/// Whether the bottom sheet can be dragged.
final bool? enableDrag;
/// The elevation color of the top bar.
final Color? topBarShadowColor;
/// The elevation of the top bar.
final double? topBarElevation;
/// The height of the hero image.
final double? heroImageHeight;
/// Indicates whether a gentle gradient overlay should be rendered above the
/// [stickyActionBar]. The purpose of this gradient is to visually suggest
/// to the user that additional content might be present below the action bar.
///
/// If set to `true`, a gradient from the page's background color to transparent
/// is rendered right above the [stickyActionBar]. If `false`, no gradient is rendered.
/// By default, it's set to `true` in [WoltModalSheetThemeData].
final bool? hasSabGradient;
/// The color of the gentle gradient overlay that is rendered above the [stickyActionBar]. The
/// purpose of this gradient is to visually suggest to the user that additional content might
/// be present below the action bar.
///
/// If [hasSabGradient] set to `true`, a gradient from this color to transparent is rendered
/// right above the [stickyActionBar]. If `false`, no gradient is rendered. By default, it's
/// value is to page background color.
final Color? sabGradientColor;
/// If [hasSabGradient] set to `true`, a gradient from the page's background color to transparent
/// is rendered right above the [stickyActionBar]. [sabGradientHeight] sets the height of this
/// transparency.
final double? sabGradientHeight;
/// The height of the navigation bar.
final double? navBarHeight;
/// Whether to show a top bar layer above the modal sheet.
final bool? hasTopBarLayer;
/// Whether the top bar layer is always visible.
final bool? isTopBarLayerAlwaysVisible;
/// The minimum width of the dialog.
final double? minDialogWidth;
/// The maximum width of the dialog.
final double? maxDialogWidth;
/// The minimum height of the page.
final double? minPageHeight;
/// The maximum height of the page.
final double? maxPageHeight;
/// Overrides the default value for [WoltModalSheetThemeData] shadowColor.
final Color? shadowColor;
/// Overrides the default value for [WoltModalSheet] clipBehavior.
///
/// If null, [WoltModalSheet] uses [Clip.antiAliasWithSaveLayer].
final Clip? clipBehavior;
/// The default value for [WoltModalSheet] scrollPhysics in the main content.
final ScrollPhysics? mainContentScrollPhysics;
/// Motion animation styles for both pagination and scrolling animations.
final WoltModalSheetAnimationStyle? animationStyle;
/// If there is an onscreen keyboard displayed above the
/// modal sheet, the main content can be resized to avoid overlapping the keyboard, which
/// prevents widgets inside the main content from being obscured by the keyboard.
///
/// WoltModalSheet internally uses a [Scaffold] to provide this functionality and to handle the
/// safe area color for the modal sheet. Setting this value will set the same value inside the
/// internal [Scaffold] of the modal sheet.
///
/// Defaults to true.
final bool? resizeToAvoidBottomInset;
@override
WoltModalSheetThemeData copyWith({
Color? backgroundColor,
double? modalElevation,
Color? modalBarrierColor,
ShapeBorder? bottomSheetShape,
ShapeBorder? dialogShape,
bool? showDragHandle,
Color? dragHandleColor,
Size? dragHandleSize,
Color? topBarShadowColor,
double? topBarElevation,
double? heroImageHeight,
bool? hasSabGradient,
double? sabGradientHeight,
double? navBarHeight,
bool? hasTopBarLayer,
bool? isTopBarLayerAlwaysVisible,
double? minDialogWidth,
double? maxDialogWidth,
double? minPageHeight,
double? maxPageHeight,
Color? surfaceTintColor,
Color? shadowColor,
Clip? clipBehavior,
ScrollPhysics? mainContentScrollPhysics,
WoltModalSheetAnimationStyle? animationStyle,
bool? resizeToAvoidBottomInset,
}) {
return WoltModalSheetThemeData(
backgroundColor: backgroundColor ?? this.backgroundColor,
modalElevation: modalElevation ?? this.modalElevation,
modalBarrierColor: modalBarrierColor ?? this.modalBarrierColor,
bottomSheetShape: bottomSheetShape ?? this.bottomSheetShape,
dialogShape: dialogShape ?? this.dialogShape,
showDragHandle: showDragHandle ?? this.showDragHandle,
dragHandleColor: dragHandleColor ?? this.dragHandleColor,
dragHandleSize: dragHandleSize ?? this.dragHandleSize,
topBarShadowColor: topBarShadowColor ?? this.topBarShadowColor,
topBarElevation: topBarElevation ?? this.topBarElevation,
heroImageHeight: heroImageHeight ?? this.heroImageHeight,
hasSabGradient: hasSabGradient ?? this.hasSabGradient,
sabGradientHeight: sabGradientHeight ?? this.sabGradientHeight,
navBarHeight: navBarHeight ?? this.navBarHeight,
hasTopBarLayer: hasTopBarLayer ?? this.hasTopBarLayer,
isTopBarLayerAlwaysVisible:
isTopBarLayerAlwaysVisible ?? this.isTopBarLayerAlwaysVisible,
minDialogWidth: minDialogWidth ?? this.minDialogWidth,
maxDialogWidth: maxDialogWidth ?? this.maxDialogWidth,
minPageHeight: minPageHeight ?? this.minPageHeight,
maxPageHeight: maxPageHeight ?? this.maxPageHeight,
surfaceTintColor: surfaceTintColor ?? this.surfaceTintColor,
shadowColor: shadowColor ?? this.shadowColor,
clipBehavior: clipBehavior ?? this.clipBehavior,
mainContentScrollPhysics:
mainContentScrollPhysics ?? this.mainContentScrollPhysics,
animationStyle: animationStyle ?? this.animationStyle,
resizeToAvoidBottomInset:
resizeToAvoidBottomInset ?? this.resizeToAvoidBottomInset,
);
}
@override
WoltModalSheetThemeData lerp(WoltModalSheetThemeData? other, double t) {
if (other == null) return this;
return WoltModalSheetThemeData(
backgroundColor: Color.lerp(backgroundColor, other.backgroundColor, t),
modalElevation: lerpDouble(modalElevation, other.modalElevation, t),
showDragHandle: t < 0.5 ? showDragHandle : other.showDragHandle,
resizeToAvoidBottomInset:
t < 0.5 ? resizeToAvoidBottomInset : other.resizeToAvoidBottomInset,
modalBarrierColor:
Color.lerp(modalBarrierColor, other.modalBarrierColor, t),
bottomSheetShape:
ShapeBorder.lerp(bottomSheetShape, other.bottomSheetShape, t),
dialogShape: ShapeBorder.lerp(dialogShape, other.dialogShape, t),
dragHandleColor: Color.lerp(dragHandleColor, other.dragHandleColor, t),
dragHandleSize: Size.lerp(dragHandleSize, other.dragHandleSize, t),
topBarShadowColor:
Color.lerp(topBarShadowColor, other.topBarShadowColor, t),
topBarElevation: lerpDouble(topBarElevation, other.topBarElevation, t),
heroImageHeight: lerpDouble(heroImageHeight, other.heroImageHeight, t),
hasSabGradient: t < 0.5 ? hasSabGradient : other.hasSabGradient,
sabGradientHeight:
lerpDouble(sabGradientHeight, other.sabGradientHeight, t),
navBarHeight: lerpDouble(navBarHeight, other.navBarHeight, t),
hasTopBarLayer: t < 0.5 ? hasTopBarLayer : other.hasTopBarLayer,
isTopBarLayerAlwaysVisible: t < 0.5
? isTopBarLayerAlwaysVisible
: other.isTopBarLayerAlwaysVisible,
minDialogWidth: lerpDouble(minDialogWidth, other.minDialogWidth, t),
maxDialogWidth: lerpDouble(maxDialogWidth, other.maxDialogWidth, t),
minPageHeight: lerpDouble(minPageHeight, other.minPageHeight, t),
maxPageHeight: lerpDouble(maxPageHeight, other.maxPageHeight, t),
surfaceTintColor: Color.lerp(surfaceTintColor, other.surfaceTintColor, t),
shadowColor: Color.lerp(shadowColor, other.shadowColor, t),
clipBehavior: t < 0.5 ? clipBehavior : other.clipBehavior,
mainContentScrollPhysics:
t < 0.5 ? mainContentScrollPhysics : other.mainContentScrollPhysics,
animationStyle: t < 0.5 ? animationStyle : other.animationStyle,
);
}
}