1
+ using Unity . UIWidgets . foundation ;
2
+ using Unity . UIWidgets . painting ;
3
+ using Unity . UIWidgets . service ;
4
+ using Unity . UIWidgets . ui ;
5
+ using Unity . UIWidgets . widgets ;
6
+ using TextStyle = Unity . UIWidgets . painting . TextStyle ;
7
+
8
+ namespace Unity . UIWidgets . material {
9
+ public class ChipTheme : InheritedWidget {
10
+ public ChipTheme (
11
+ Key key = null ,
12
+ ChipThemeData data = null ,
13
+ Widget child = null
14
+ ) : base ( key : key , child : child ) {
15
+ D . assert ( child != null ) ;
16
+ D . assert ( data != null ) ;
17
+ this . data = data ;
18
+ }
19
+
20
+ public readonly ChipThemeData data ;
21
+
22
+ public static ChipThemeData of ( BuildContext context ) {
23
+ ChipTheme inheritedTheme = ( ChipTheme ) context . inheritFromWidgetOfExactType ( typeof ( ChipTheme ) ) ;
24
+ return inheritedTheme ? . data ?? Theme . of ( context ) . chipTheme ;
25
+ }
26
+
27
+ public override bool updateShouldNotify ( InheritedWidget _oldWidget ) {
28
+ ChipTheme oldWidget = _oldWidget as ChipTheme ;
29
+ return this . data != oldWidget . data ;
30
+ }
31
+ }
32
+
33
+ public class ChipThemeData : Diagnosticable {
34
+ public ChipThemeData (
35
+ Color backgroundColor = null ,
36
+ Color deleteIconColor = null ,
37
+ Color disabledColor = null ,
38
+ Color selectedColor = null ,
39
+ Color secondarySelectedColor = null ,
40
+ EdgeInsets labelPadding = null ,
41
+ EdgeInsets padding = null ,
42
+ ShapeBorder shape = null ,
43
+ TextStyle labelStyle = null ,
44
+ TextStyle secondaryLabelStyle = null ,
45
+ Brightness ? brightness = null ,
46
+ float ? elevation = null ,
47
+ float ? pressElevation = null
48
+ ) {
49
+ D . assert ( backgroundColor != null ) ;
50
+ D . assert ( disabledColor != null ) ;
51
+ D . assert ( selectedColor != null ) ;
52
+ D . assert ( secondarySelectedColor != null ) ;
53
+ D . assert ( labelPadding != null ) ;
54
+ D . assert ( padding != null ) ;
55
+ D . assert ( shape != null ) ;
56
+ D . assert ( labelStyle != null ) ;
57
+ D . assert ( secondaryLabelStyle != null ) ;
58
+ D . assert ( brightness != null ) ;
59
+ this . backgroundColor = backgroundColor ;
60
+ this . deleteIconColor = deleteIconColor ;
61
+ this . disabledColor = disabledColor ;
62
+ this . selectedColor = selectedColor ;
63
+ this . secondarySelectedColor = secondarySelectedColor ;
64
+ this . labelPadding = labelPadding ;
65
+ this . padding = padding ;
66
+ this . shape = shape ;
67
+ this . labelStyle = labelStyle ;
68
+ this . secondaryLabelStyle = secondaryLabelStyle ;
69
+ this . brightness = brightness ;
70
+ this . elevation = elevation ;
71
+ this . pressElevation = pressElevation ;
72
+ }
73
+
74
+ public static ChipThemeData fromDefaults (
75
+ Brightness ? brightness = null ,
76
+ Color primaryColor = null ,
77
+ Color secondaryColor = null ,
78
+ TextStyle labelStyle = null
79
+ ) {
80
+ D . assert ( primaryColor != null || brightness != null ,
81
+ "One of primaryColor or brightness must be specified" ) ;
82
+ D . assert ( primaryColor == null || brightness == null ,
83
+ "Only one of primaryColor or brightness may be specified" ) ;
84
+ D . assert ( secondaryColor != null ) ;
85
+ D . assert ( labelStyle != null ) ;
86
+
87
+ if ( primaryColor != null ) {
88
+ brightness = ThemeData . estimateBrightnessForColor ( primaryColor ) ;
89
+ }
90
+
91
+ const int backgroundAlpha = 0x1f ; // 12%
92
+ const int deleteIconAlpha = 0xde ; // 87%
93
+ const int disabledAlpha = 0x0c ; // 38% * 12% = 5%
94
+ const int selectAlpha = 0x3d ; // 12% + 12% = 24%
95
+ const int textLabelAlpha = 0xde ; // 87%
96
+ ShapeBorder shape = new StadiumBorder ( ) ;
97
+ EdgeInsets labelPadding = EdgeInsets . symmetric ( horizontal : 8.0f ) ;
98
+ EdgeInsets padding = EdgeInsets . all ( 4.0f ) ;
99
+
100
+ primaryColor = primaryColor ?? ( brightness == Brightness . light ? Colors . black : Colors . white ) ;
101
+ Color backgroundColor = primaryColor . withAlpha ( backgroundAlpha ) ;
102
+ Color deleteIconColor = primaryColor . withAlpha ( deleteIconAlpha ) ;
103
+ Color disabledColor = primaryColor . withAlpha ( disabledAlpha ) ;
104
+ Color selectedColor = primaryColor . withAlpha ( selectAlpha ) ;
105
+ Color secondarySelectedColor = secondaryColor . withAlpha ( selectAlpha ) ;
106
+ TextStyle secondaryLabelStyle = labelStyle . copyWith (
107
+ color : secondaryColor . withAlpha ( textLabelAlpha )
108
+ ) ;
109
+ labelStyle = labelStyle . copyWith ( color : primaryColor . withAlpha ( textLabelAlpha ) ) ;
110
+
111
+ return new ChipThemeData (
112
+ backgroundColor : backgroundColor ,
113
+ deleteIconColor : deleteIconColor ,
114
+ disabledColor : disabledColor ,
115
+ selectedColor : selectedColor ,
116
+ secondarySelectedColor : secondarySelectedColor ,
117
+ labelPadding : labelPadding ,
118
+ padding : padding ,
119
+ shape : shape ,
120
+ labelStyle : labelStyle ,
121
+ secondaryLabelStyle : secondaryLabelStyle ,
122
+ brightness : brightness
123
+ ) ;
124
+ }
125
+
126
+ public readonly Color backgroundColor ;
127
+
128
+ public readonly Color deleteIconColor ;
129
+
130
+ public readonly Color disabledColor ;
131
+
132
+ public readonly Color selectedColor ;
133
+
134
+ public readonly Color secondarySelectedColor ;
135
+
136
+ public readonly EdgeInsets labelPadding ;
137
+
138
+ public readonly EdgeInsets padding ;
139
+
140
+ public readonly ShapeBorder shape ;
141
+
142
+ public readonly TextStyle labelStyle ;
143
+
144
+ public readonly TextStyle secondaryLabelStyle ;
145
+
146
+ public readonly Brightness ? brightness ;
147
+
148
+ public readonly float ? elevation ;
149
+
150
+ public readonly float ? pressElevation ;
151
+
152
+ public ChipThemeData copyWith (
153
+ Color backgroundColor = null ,
154
+ Color deleteIconColor = null ,
155
+ Color disabledColor = null ,
156
+ Color selectedColor = null ,
157
+ Color secondarySelectedColor = null ,
158
+ EdgeInsets labelPadding = null ,
159
+ EdgeInsets padding = null ,
160
+ ShapeBorder shape = null ,
161
+ TextStyle labelStyle = null ,
162
+ TextStyle secondaryLabelStyle = null ,
163
+ Brightness ? brightness = null ,
164
+ float ? elevation = null ,
165
+ float ? pressElevation = null
166
+ ) {
167
+ return new ChipThemeData (
168
+ backgroundColor : backgroundColor ?? this . backgroundColor ,
169
+ deleteIconColor : deleteIconColor ?? this . deleteIconColor ,
170
+ disabledColor : disabledColor ?? this . disabledColor ,
171
+ selectedColor : selectedColor ?? this . selectedColor ,
172
+ secondarySelectedColor : secondarySelectedColor ?? this . secondarySelectedColor ,
173
+ labelPadding : labelPadding ?? this . labelPadding ,
174
+ padding : padding ?? this . padding ,
175
+ shape : shape ?? this . shape ,
176
+ labelStyle : labelStyle ?? this . labelStyle ,
177
+ secondaryLabelStyle : secondaryLabelStyle ?? this . secondaryLabelStyle ,
178
+ brightness : brightness ?? this . brightness ,
179
+ elevation : elevation ?? this . elevation ,
180
+ pressElevation : pressElevation ?? this . pressElevation
181
+ ) ;
182
+ }
183
+
184
+ public static ChipThemeData lerp ( ChipThemeData a , ChipThemeData b , float t ) {
185
+ D . assert ( t != null ) ;
186
+ if ( a == null && b == null ) {
187
+ return null ;
188
+ }
189
+
190
+ return new ChipThemeData (
191
+ backgroundColor : Color . lerp ( a ? . backgroundColor , b ? . backgroundColor , t ) ,
192
+ deleteIconColor : Color . lerp ( a ? . deleteIconColor , b ? . deleteIconColor , t ) ,
193
+ disabledColor : Color . lerp ( a ? . disabledColor , b ? . disabledColor , t ) ,
194
+ selectedColor : Color . lerp ( a ? . selectedColor , b ? . selectedColor , t ) ,
195
+ secondarySelectedColor : Color . lerp ( a ? . secondarySelectedColor , b ? . secondarySelectedColor , t ) ,
196
+ labelPadding : EdgeInsets . lerp ( a ? . labelPadding , b ? . labelPadding , t ) ,
197
+ padding : EdgeInsets . lerp ( a ? . padding , b ? . padding , t ) ,
198
+ shape : ShapeBorder . lerp ( a ? . shape , b ? . shape , t ) ,
199
+ labelStyle : TextStyle . lerp ( a ? . labelStyle , b ? . labelStyle , t ) ,
200
+ secondaryLabelStyle : TextStyle . lerp ( a ? . secondaryLabelStyle , b ? . secondaryLabelStyle , t ) ,
201
+ brightness : t < 0.5f ? a ? . brightness ?? Brightness . light : b ? . brightness ?? Brightness . light ,
202
+ elevation : MathUtils . lerpFloat ( a ? . elevation ?? 0.0f , b ? . elevation ?? 0.0f , t ) ,
203
+ pressElevation : MathUtils . lerpFloat ( a ? . pressElevation ?? 0.0f , b ? . pressElevation ?? 0.0f , t )
204
+ ) ;
205
+ }
206
+
207
+ public override int GetHashCode ( ) {
208
+ var hashCode = this . backgroundColor . GetHashCode ( ) ;
209
+ hashCode = ( hashCode * 397 ) ^ this . deleteIconColor . GetHashCode ( ) ;
210
+ hashCode = ( hashCode * 397 ) ^ this . disabledColor . GetHashCode ( ) ;
211
+ hashCode = ( hashCode * 397 ) ^ this . selectedColor . GetHashCode ( ) ;
212
+ hashCode = ( hashCode * 397 ) ^ this . secondarySelectedColor . GetHashCode ( ) ;
213
+ hashCode = ( hashCode * 397 ) ^ this . labelPadding . GetHashCode ( ) ;
214
+ hashCode = ( hashCode * 397 ) ^ this . padding . GetHashCode ( ) ;
215
+ hashCode = ( hashCode * 397 ) ^ this . shape . GetHashCode ( ) ;
216
+ hashCode = ( hashCode * 397 ) ^ this . labelStyle . GetHashCode ( ) ;
217
+ hashCode = ( hashCode * 397 ) ^ this . secondaryLabelStyle . GetHashCode ( ) ;
218
+ hashCode = ( hashCode * 397 ) ^ this . brightness . GetHashCode ( ) ;
219
+ hashCode = ( hashCode * 397 ) ^ this . elevation . GetHashCode ( ) ;
220
+ hashCode = ( hashCode * 397 ) ^ this . pressElevation . GetHashCode ( ) ;
221
+ return hashCode ;
222
+ }
223
+
224
+ public bool Equals ( ChipThemeData other ) {
225
+ return other . backgroundColor == this . backgroundColor
226
+ && other . deleteIconColor == this . deleteIconColor
227
+ && other . disabledColor == this . disabledColor
228
+ && other . selectedColor == this . selectedColor
229
+ && other . secondarySelectedColor == this . secondarySelectedColor
230
+ && other . labelPadding == this . labelPadding
231
+ && other . padding == this . padding
232
+ && other . shape == this . shape
233
+ && other . labelStyle == this . labelStyle
234
+ && other . secondaryLabelStyle == this . secondaryLabelStyle
235
+ && other . brightness == this . brightness
236
+ && other . elevation == this . elevation
237
+ && other . pressElevation == this . pressElevation ;
238
+ }
239
+
240
+ public override bool Equals ( object obj ) {
241
+ if ( ReferenceEquals ( null , obj ) ) {
242
+ return false ;
243
+ }
244
+
245
+ if ( ReferenceEquals ( this , obj ) ) {
246
+ return true ;
247
+ }
248
+
249
+ if ( obj . GetType ( ) != this . GetType ( ) ) {
250
+ return false ;
251
+ }
252
+
253
+ return this . Equals ( ( ChipThemeData ) obj ) ;
254
+ }
255
+
256
+ public static bool operator == ( ChipThemeData left , ChipThemeData right ) {
257
+ return Equals ( left , right ) ;
258
+ }
259
+
260
+ public static bool operator != ( ChipThemeData left , ChipThemeData right ) {
261
+ return ! Equals ( left , right ) ;
262
+ }
263
+
264
+ public override void debugFillProperties ( DiagnosticPropertiesBuilder properties ) {
265
+ base . debugFillProperties ( properties ) ;
266
+ ThemeData defaultTheme = ThemeData . fallback ( ) ;
267
+ ChipThemeData defaultData = fromDefaults (
268
+ secondaryColor : defaultTheme . primaryColor ,
269
+ brightness : defaultTheme . brightness ,
270
+ labelStyle : defaultTheme . textTheme . body2
271
+ ) ;
272
+ properties . add ( new DiagnosticsProperty < Color > ( "backgroundColor" , this . backgroundColor ,
273
+ defaultValue : defaultData . backgroundColor ) ) ;
274
+ properties . add ( new DiagnosticsProperty < Color > ( "deleteIconColor" , this . deleteIconColor ,
275
+ defaultValue : defaultData . deleteIconColor ) ) ;
276
+ properties . add ( new DiagnosticsProperty < Color > ( "disabledColor" , this . disabledColor ,
277
+ defaultValue : defaultData . disabledColor ) ) ;
278
+ properties . add ( new DiagnosticsProperty < Color > ( "selectedColor" , this . selectedColor ,
279
+ defaultValue : defaultData . selectedColor ) ) ;
280
+ properties . add ( new DiagnosticsProperty < Color > ( "secondarySelectedColor" , this . secondarySelectedColor ,
281
+ defaultValue : defaultData . secondarySelectedColor ) ) ;
282
+ properties . add ( new DiagnosticsProperty < EdgeInsets > ( "labelPadding" , this . labelPadding ,
283
+ defaultValue : defaultData . labelPadding ) ) ;
284
+ properties . add (
285
+ new DiagnosticsProperty < EdgeInsets > ( "padding" , this . padding , defaultValue : defaultData . padding ) ) ;
286
+ properties . add ( new DiagnosticsProperty < ShapeBorder > ( "shape" , this . shape , defaultValue : defaultData . shape ) ) ;
287
+ properties . add ( new DiagnosticsProperty < TextStyle > ( "labelStyle" , this . labelStyle ,
288
+ defaultValue : defaultData . labelStyle ) ) ;
289
+ properties . add ( new DiagnosticsProperty < TextStyle > ( "secondaryLabelStyle" , this . secondaryLabelStyle ,
290
+ defaultValue : defaultData . secondaryLabelStyle ) ) ;
291
+ properties . add ( new EnumProperty < Brightness ? > ( "brightness" , this . brightness ,
292
+ defaultValue : defaultData . brightness ) ) ;
293
+ properties . add ( new FloatProperty ( "elevation" , this . elevation , defaultValue : defaultData . elevation ) ) ;
294
+ properties . add ( new FloatProperty ( "pressElevation" , this . pressElevation ,
295
+ defaultValue : defaultData . pressElevation ) ) ;
296
+ }
297
+ }
298
+ }
0 commit comments