-
Notifications
You must be signed in to change notification settings - Fork 30.3k
Expand file tree
/
Copy pathtext_theme.dart
More file actions
448 lines (402 loc) · 15.2 KB
/
text_theme.dart
File metadata and controls
448 lines (402 loc) · 15.2 KB
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/// @docImport 'interface_level.dart';
/// @docImport 'theme.dart';
library;
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'colors.dart';
// Please update _TextThemeDefaultsBuilder accordingly after changing the default
// color here, as their implementation depends on the default value of the color
// field.
//
// Values derived from https://developer.apple.com/design/resources/.
const TextStyle _kDefaultTextStyle = TextStyle(
inherit: false,
fontFamily: 'CupertinoSystemText',
fontSize: 17.0,
letterSpacing: -0.41,
color: CupertinoColors.label,
decoration: TextDecoration.none,
);
// Please update _TextThemeDefaultsBuilder accordingly after changing the default
// color here, as their implementation depends on the default value of the color
// field.
//
// Values derived from https://developer.apple.com/design/resources/.
// See [iOS 17 + iPadOS 17 UI Kit](https://www.figma.com/community/file/1248375255495415511) for details.
const TextStyle _kDefaultActionTextStyle = TextStyle(
inherit: false,
fontFamily: 'CupertinoSystemText',
fontSize: 17.0,
letterSpacing: -0.41,
color: CupertinoColors.activeBlue,
decoration: TextDecoration.none,
);
// Please update _TextThemeDefaultsBuilder accordingly after changing the default
// color here, as their implementation depends on the default value of the color
// field.
//
// Values derived from https://developer.apple.com/design/resources/.
// See [iOS 17 + iPadOS 17 UI Kit](https://www.figma.com/community/file/1248375255495415511) for details.
const TextStyle _kDefaultActionSmallTextStyle = TextStyle(
inherit: false,
fontFamily: 'CupertinoSystemText',
fontSize: 15.0,
letterSpacing: -0.23,
color: CupertinoColors.activeBlue,
decoration: TextDecoration.none,
);
// Please update _TextThemeDefaultsBuilder accordingly after changing the default
// color here, as their implementation depends on the default value of the color
// field.
//
// Values derived from https://developer.apple.com/design/resources/.
const TextStyle _kDefaultTabLabelTextStyle = TextStyle(
inherit: false,
fontFamily: 'CupertinoSystemText',
fontSize: 10.0,
fontWeight: FontWeight.w500,
letterSpacing: -0.24,
color: CupertinoColors.inactiveGray,
);
const TextStyle _kDefaultMiddleTitleTextStyle = TextStyle(
inherit: false,
fontFamily: 'CupertinoSystemText',
fontSize: 17.0,
fontWeight: FontWeight.w600,
letterSpacing: -0.41,
color: CupertinoColors.label,
);
const TextStyle _kDefaultLargeTitleTextStyle = TextStyle(
inherit: false,
fontFamily: 'CupertinoSystemDisplay',
fontSize: 34.0,
fontWeight: FontWeight.w700,
letterSpacing: 0.38,
color: CupertinoColors.label,
);
// Please update _TextThemeDefaultsBuilder accordingly after changing the default
// color here, as their implementation depends on the default value of the color
// field.
//
// Inspected on iOS 13 simulator with "Debug View Hierarchy".
// Value extracted from off-center labels. Centered labels have a font size of 25pt.
//
// The letterSpacing sourced from iOS 14 simulator screenshots for comparison.
// See also:
//
// * https://github.com/flutter/flutter/pull/65501#discussion_r486557093
const TextStyle _kDefaultPickerTextStyle = TextStyle(
inherit: false,
fontFamily: 'CupertinoSystemDisplay',
fontSize: 21.0,
fontWeight: FontWeight.w400,
letterSpacing: -0.6,
color: CupertinoColors.label,
);
// Please update _TextThemeDefaultsBuilder accordingly after changing the default
// color here, as their implementation depends on the default value of the color
// field.
//
// Inspected on iOS 13 simulator with "Debug View Hierarchy".
// Value extracted from off-center labels. Centered labels have a font size of 25pt.
const TextStyle _kDefaultDateTimePickerTextStyle = TextStyle(
inherit: false,
fontFamily: 'CupertinoSystemDisplay',
fontSize: 21,
letterSpacing: 0.4,
fontWeight: FontWeight.normal,
color: CupertinoColors.label,
);
TextStyle? _resolveTextStyle(TextStyle? style, BuildContext context) {
// This does not resolve the shadow color, foreground, background, etc.
return style?.copyWith(
color: CupertinoDynamicColor.maybeResolve(style.color, context),
backgroundColor: CupertinoDynamicColor.maybeResolve(style.backgroundColor, context),
decorationColor: CupertinoDynamicColor.maybeResolve(style.decorationColor, context),
);
}
/// Cupertino typography theme in a [CupertinoThemeData].
@immutable
class CupertinoTextThemeData with Diagnosticable {
/// Create a [CupertinoTextThemeData].
///
/// The [primaryColor] is used to derive TextStyle defaults of other attributes
/// such as [navActionTextStyle] and [actionTextStyle]. It must not be null when
/// either [navActionTextStyle] or [actionTextStyle] is null. Defaults to
/// [CupertinoColors.systemBlue].
///
/// Other [TextStyle] parameters default to default iOS text styles when
/// unspecified.
const CupertinoTextThemeData({
Color primaryColor = CupertinoColors.systemBlue,
TextStyle? textStyle,
TextStyle? actionTextStyle,
TextStyle? actionSmallTextStyle,
TextStyle? tabLabelTextStyle,
TextStyle? navTitleTextStyle,
TextStyle? navLargeTitleTextStyle,
TextStyle? navActionTextStyle,
TextStyle? pickerTextStyle,
TextStyle? dateTimePickerTextStyle,
}) : this._raw(
const _TextThemeDefaultsBuilder(CupertinoColors.label, CupertinoColors.inactiveGray),
primaryColor,
textStyle,
actionTextStyle,
actionSmallTextStyle,
tabLabelTextStyle,
navTitleTextStyle,
navLargeTitleTextStyle,
navActionTextStyle,
pickerTextStyle,
dateTimePickerTextStyle,
);
const CupertinoTextThemeData._raw(
this._defaults,
this._primaryColor,
this._textStyle,
this._actionTextStyle,
this._actionSmallTextStyle,
this._tabLabelTextStyle,
this._navTitleTextStyle,
this._navLargeTitleTextStyle,
this._navActionTextStyle,
this._pickerTextStyle,
this._dateTimePickerTextStyle,
) : assert((_navActionTextStyle != null && _actionTextStyle != null) || _primaryColor != null);
final _TextThemeDefaultsBuilder _defaults;
final Color? _primaryColor;
final TextStyle? _textStyle;
/// The [TextStyle] of general text content for Cupertino widgets.
TextStyle get textStyle => _textStyle ?? _defaults.textStyle;
final TextStyle? _actionTextStyle;
/// The [TextStyle] of interactive text content such as text in a button without background.
TextStyle get actionTextStyle {
return _actionTextStyle ?? _defaults.actionTextStyle(primaryColor: _primaryColor);
}
final TextStyle? _actionSmallTextStyle;
/// The [TextStyle] of interactive text content such as text in a small button.
TextStyle get actionSmallTextStyle {
return _actionSmallTextStyle ?? _defaults.actionSmallTextStyle(primaryColor: _primaryColor);
}
final TextStyle? _tabLabelTextStyle;
/// The [TextStyle] of unselected tabs.
TextStyle get tabLabelTextStyle => _tabLabelTextStyle ?? _defaults.tabLabelTextStyle;
final TextStyle? _navTitleTextStyle;
/// The [TextStyle] of titles in standard navigation bars.
TextStyle get navTitleTextStyle => _navTitleTextStyle ?? _defaults.navTitleTextStyle;
final TextStyle? _navLargeTitleTextStyle;
/// The [TextStyle] of large titles in sliver navigation bars.
TextStyle get navLargeTitleTextStyle =>
_navLargeTitleTextStyle ?? _defaults.navLargeTitleTextStyle;
final TextStyle? _navActionTextStyle;
/// The [TextStyle] of interactive text content in navigation bars.
TextStyle get navActionTextStyle {
return _navActionTextStyle ?? _defaults.navActionTextStyle(primaryColor: _primaryColor);
}
final TextStyle? _pickerTextStyle;
/// The [TextStyle] of pickers.
TextStyle get pickerTextStyle => _pickerTextStyle ?? _defaults.pickerTextStyle;
final TextStyle? _dateTimePickerTextStyle;
/// The [TextStyle] of date time pickers.
TextStyle get dateTimePickerTextStyle =>
_dateTimePickerTextStyle ?? _defaults.dateTimePickerTextStyle;
/// Returns a copy of the current [CupertinoTextThemeData] with all the colors
/// resolved against the given [BuildContext].
///
/// If any of the [InheritedWidget]s required to resolve this
/// [CupertinoTextThemeData] is not found in [context], any unresolved
/// [CupertinoDynamicColor]s will use the default trait value
/// ([Brightness.light] platform brightness, normal contrast,
/// [CupertinoUserInterfaceLevelData.base] elevation level).
CupertinoTextThemeData resolveFrom(BuildContext context) {
return CupertinoTextThemeData._raw(
_defaults.resolveFrom(context),
CupertinoDynamicColor.maybeResolve(_primaryColor, context),
_resolveTextStyle(_textStyle, context),
_resolveTextStyle(_actionTextStyle, context),
_resolveTextStyle(_actionSmallTextStyle, context),
_resolveTextStyle(_tabLabelTextStyle, context),
_resolveTextStyle(_navTitleTextStyle, context),
_resolveTextStyle(_navLargeTitleTextStyle, context),
_resolveTextStyle(_navActionTextStyle, context),
_resolveTextStyle(_pickerTextStyle, context),
_resolveTextStyle(_dateTimePickerTextStyle, context),
);
}
/// Returns a copy of the current [CupertinoTextThemeData] instance with
/// specified overrides.
CupertinoTextThemeData copyWith({
Color? primaryColor,
TextStyle? textStyle,
TextStyle? actionTextStyle,
TextStyle? actionSmallTextStyle,
TextStyle? tabLabelTextStyle,
TextStyle? navTitleTextStyle,
TextStyle? navLargeTitleTextStyle,
TextStyle? navActionTextStyle,
TextStyle? pickerTextStyle,
TextStyle? dateTimePickerTextStyle,
}) {
return CupertinoTextThemeData._raw(
_defaults,
primaryColor ?? _primaryColor,
textStyle ?? _textStyle,
actionTextStyle ?? _actionTextStyle,
actionSmallTextStyle ?? _actionSmallTextStyle,
tabLabelTextStyle ?? _tabLabelTextStyle,
navTitleTextStyle ?? _navTitleTextStyle,
navLargeTitleTextStyle ?? _navLargeTitleTextStyle,
navActionTextStyle ?? _navActionTextStyle,
pickerTextStyle ?? _pickerTextStyle,
dateTimePickerTextStyle ?? _dateTimePickerTextStyle,
);
}
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
const defaultData = CupertinoTextThemeData();
properties.add(
DiagnosticsProperty<TextStyle>('textStyle', textStyle, defaultValue: defaultData.textStyle),
);
properties.add(
DiagnosticsProperty<TextStyle>(
'actionTextStyle',
actionTextStyle,
defaultValue: defaultData.actionTextStyle,
),
);
properties.add(
DiagnosticsProperty<TextStyle>(
'actionSmallTextStyle',
actionSmallTextStyle,
defaultValue: defaultData.actionSmallTextStyle,
),
);
properties.add(
DiagnosticsProperty<TextStyle>(
'tabLabelTextStyle',
tabLabelTextStyle,
defaultValue: defaultData.tabLabelTextStyle,
),
);
properties.add(
DiagnosticsProperty<TextStyle>(
'navTitleTextStyle',
navTitleTextStyle,
defaultValue: defaultData.navTitleTextStyle,
),
);
properties.add(
DiagnosticsProperty<TextStyle>(
'navLargeTitleTextStyle',
navLargeTitleTextStyle,
defaultValue: defaultData.navLargeTitleTextStyle,
),
);
properties.add(
DiagnosticsProperty<TextStyle>(
'navActionTextStyle',
navActionTextStyle,
defaultValue: defaultData.navActionTextStyle,
),
);
properties.add(
DiagnosticsProperty<TextStyle>(
'pickerTextStyle',
pickerTextStyle,
defaultValue: defaultData.pickerTextStyle,
),
);
properties.add(
DiagnosticsProperty<TextStyle>(
'dateTimePickerTextStyle',
dateTimePickerTextStyle,
defaultValue: defaultData.dateTimePickerTextStyle,
),
);
}
@override
bool operator ==(Object other) {
if (identical(this, other)) {
return true;
}
if (other.runtimeType != runtimeType) {
return false;
}
return other is CupertinoTextThemeData &&
other._defaults == _defaults &&
other._primaryColor == _primaryColor &&
other._textStyle == _textStyle &&
other._actionTextStyle == _actionTextStyle &&
other._actionSmallTextStyle == _actionSmallTextStyle &&
other._tabLabelTextStyle == _tabLabelTextStyle &&
other._navTitleTextStyle == _navTitleTextStyle &&
other._navLargeTitleTextStyle == _navLargeTitleTextStyle &&
other._navActionTextStyle == _navActionTextStyle &&
other._pickerTextStyle == _pickerTextStyle &&
other._dateTimePickerTextStyle == _dateTimePickerTextStyle;
}
@override
int get hashCode => Object.hash(
_defaults,
_primaryColor,
_textStyle,
_actionTextStyle,
_actionSmallTextStyle,
_tabLabelTextStyle,
_navTitleTextStyle,
_navLargeTitleTextStyle,
_navActionTextStyle,
_pickerTextStyle,
_dateTimePickerTextStyle,
);
}
@immutable
class _TextThemeDefaultsBuilder {
const _TextThemeDefaultsBuilder(this.labelColor, this.inactiveGrayColor);
final Color labelColor;
final Color inactiveGrayColor;
static TextStyle _applyLabelColor(TextStyle original, Color color) {
return original.color == color ? original : original.copyWith(color: color);
}
TextStyle get textStyle => _applyLabelColor(_kDefaultTextStyle, labelColor);
TextStyle get tabLabelTextStyle =>
_applyLabelColor(_kDefaultTabLabelTextStyle, inactiveGrayColor);
TextStyle get navTitleTextStyle => _applyLabelColor(_kDefaultMiddleTitleTextStyle, labelColor);
TextStyle get navLargeTitleTextStyle =>
_applyLabelColor(_kDefaultLargeTitleTextStyle, labelColor);
TextStyle get pickerTextStyle => _applyLabelColor(_kDefaultPickerTextStyle, labelColor);
TextStyle get dateTimePickerTextStyle =>
_applyLabelColor(_kDefaultDateTimePickerTextStyle, labelColor);
TextStyle actionTextStyle({Color? primaryColor}) =>
_kDefaultActionTextStyle.copyWith(color: primaryColor);
TextStyle actionSmallTextStyle({Color? primaryColor}) =>
_kDefaultActionSmallTextStyle.copyWith(color: primaryColor);
TextStyle navActionTextStyle({Color? primaryColor}) =>
actionTextStyle(primaryColor: primaryColor);
_TextThemeDefaultsBuilder resolveFrom(BuildContext context) {
final Color resolvedLabelColor = CupertinoDynamicColor.resolve(labelColor, context);
final Color resolvedInactiveGray = CupertinoDynamicColor.resolve(inactiveGrayColor, context);
return resolvedLabelColor == labelColor && resolvedInactiveGray == CupertinoColors.inactiveGray
? this
: _TextThemeDefaultsBuilder(resolvedLabelColor, resolvedInactiveGray);
}
@override
bool operator ==(Object other) {
if (identical(this, other)) {
return true;
}
if (other.runtimeType != runtimeType) {
return false;
}
return other is _TextThemeDefaultsBuilder &&
other.labelColor == labelColor &&
other.inactiveGrayColor == inactiveGrayColor;
}
@override
int get hashCode => Object.hash(labelColor, inactiveGrayColor);
}