text_theme.dart 29.5 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8 9 10 11
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/foundation.dart';
import 'package:flutter/painting.dart';

import 'typography.dart';

/// Material design text theme.
///
12
/// Definitions for the various typographical styles found in Material Design
13 14 15 16 17 18
/// (e.g., button, caption). Rather than creating a [TextTheme] directly,
/// you can obtain an instance as [Typography.black] or [Typography.white].
///
/// To obtain the current text theme, call [Theme.of] with the current
/// [BuildContext] and read the [ThemeData.textTheme] property.
///
19 20 21 22 23 24 25 26 27 28
/// The names of the TextTheme properties match this table from the
/// [Material Design spec](https://material.io/design/typography/the-type-system.html#type-scale)
/// with two exceptions: the styles called H1-H6 in the spec are
/// headline1-headline6 in the API, and body1,body2 are called
/// bodyText1 and bodyText2.
///
/// ![](https://storage.googleapis.com/spec-host-backup/mio-design%2Fassets%2F1W8kyGVruuG_O8psvyiOaCf1lLFIMzB-N%2Ftypesystem-typescale.png)
///
/// ## Migrating from the 2014 names
///
29
/// The Material Design typography scheme was significantly changed in the
30
/// current (2018) version of the specification
31
/// ([https://material.io/design/typography](https://material.io/design/typography)).
32 33 34 35 36 37
///
/// The 2018 spec has thirteen text styles:
/// ```
/// NAME         SIZE  WEIGHT  SPACING
/// headline1    96.0  light   -1.5
/// headline2    60.0  light   -0.5
38 39 40
/// headline3    48.0  regular  0.0
/// headline4    34.0  regular  0.25
/// headline5    24.0  regular  0.0
41
/// headline6    20.0  medium   0.15
42
/// subtitle1    16.0  regular  0.15
43
/// subtitle2    14.0  medium   0.1
44 45 46 47 48
/// body1        16.0  regular  0.5   (bodyText1)
/// body2        14.0  regular  0.25  (bodyText2)
/// button       14.0  medium   1.25
/// caption      12.0  regular  0.4
/// overline     10.0  regular  1.5
49
/// ```
50 51
///
/// ...where "light" is `FontWeight.w300`, "regular" is `FontWeight.w400` and
52 53
/// "medium" is `FontWeight.w500`.
///
54
/// The [TextTheme] API was originally based on the original material (2014)
55
/// design spec, which used different text style names. For backwards
56 57 58
/// compatibility's sake, this API continues to expose the old names. The table
/// below should help with understanding the mapping of the API's old names and
/// the new names (those in terms of the 2018 material specification).
59 60 61 62 63
///
/// Each of the [TextTheme] text styles corresponds to one of the
/// styles from 2018 spec. By default, the font sizes, font weights
/// and letter spacings have not changed from their original,
/// 2014, values.
64
///
65 66 67 68 69 70 71 72 73
/// ```
/// NAME       SIZE   WEIGHT   SPACING  2018 NAME
/// display4   112.0  thin     0.0      headline1
/// display3   56.0   normal   0.0      headline2
/// display2   45.0   normal   0.0      headline3
/// display1   34.0   normal   0.0      headline4
/// headline   24.0   normal   0.0      headline5
/// title      20.0   medium   0.0      headline6
/// subhead    16.0   normal   0.0      subtitle1
74 75
/// body2      14.0   medium   0.0      body1 (bodyText1)
/// body1      14.0   normal   0.0      body2 (bodyText2)
76 77 78 79 80 81 82 83 84 85
/// caption    12.0   normal   0.0      caption
/// button     14.0   medium   0.0      button
/// subtitle   14.0   medium   0.0      subtitle2
/// overline   10.0   normal   0.0      overline
/// ```
///
/// Where "thin" is `FontWeight.w100`, "normal" is `FontWeight.w400` and
/// "medium" is `FontWeight.w500`. Letter spacing for all of the original
/// text styles was 0.0.
///
86
/// The old names are deprecated in this API.
87
///
88 89 90
/// Since the names `body1` and `body2` are used in both specifications but with
/// different meanings, the API uses the terms `bodyText1` and `bodyText2` for
/// the new API.
91
///
92 93
/// To configure a [Theme] for the new sizes, weights, and letter spacings,
/// initialize its [ThemeData.typography] value using [Typography.material2018].
94 95 96 97 98 99
///
/// See also:
///
///  * [Typography], the class that generates [TextTheme]s appropriate for a platform.
///  * [Theme], for other aspects of a material design application that can be
///    globally adjusted, such as the color scheme.
100
///  * <https://material.io/design/typography/>
101
@immutable
102
class TextTheme with Diagnosticable {
103 104 105 106 107 108
  /// Creates a text theme that uses the given values.
  ///
  /// Rather than creating a new text theme, consider using [Typography.black]
  /// or [Typography.white], which implement the typography styles in the
  /// material design specification:
  ///
109
  /// <https://material.io/design/typography/#type-scale>
110 111 112 113
  ///
  /// If you do decide to create your own text theme, consider using one of
  /// those predefined themes as a starting point for [copyWith] or [apply].
  const TextTheme({
114 115 116 117 118 119 120 121 122 123
    TextStyle? headline1,
    TextStyle? headline2,
    TextStyle? headline3,
    TextStyle? headline4,
    TextStyle? headline5,
    TextStyle? headline6,
    TextStyle? subtitle1,
    TextStyle? subtitle2,
    TextStyle? bodyText1,
    TextStyle? bodyText2,
124 125 126
    this.caption,
    this.button,
    this.overline,
127 128
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline1. '
129
      'This feature was deprecated after v1.13.8.',
130
    )
131
    TextStyle? display4,
132 133
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline2. '
134
      'This feature was deprecated after v1.13.8.',
135
    )
136
    TextStyle? display3,
137 138
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline3. '
139
      'This feature was deprecated after v1.13.8.',
140
    )
141
    TextStyle? display2,
142 143
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline4. '
144
      'This feature was deprecated after v1.13.8.',
145
    )
146
    TextStyle? display1,
147 148
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline5. '
149
      'This feature was deprecated after v1.13.8.',
150
    )
151
    TextStyle? headline,
152 153
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline6. '
154
      'This feature was deprecated after v1.13.8.',
155
    )
156
    TextStyle? title,
157 158
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is subtitle1. '
159
      'This feature was deprecated after v1.13.8.',
160
    )
161
    TextStyle? subhead,
162 163
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is subtitle2. '
164
      'This feature was deprecated after v1.13.8.',
165
    )
166
    TextStyle? subtitle,
167 168
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is bodyText1. '
169
      'This feature was deprecated after v1.13.8.',
170
    )
171
    TextStyle? body2,
172 173
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is bodyText2. '
174
      'This feature was deprecated after v1.13.8.',
175
    )
176
    TextStyle? body1,
177 178 179 180 181 182
  }) : assert(
         (headline1 == null && headline2 == null && headline3 == null && headline4 == null && headline5 == null && headline6 == null &&
          subtitle1 == null && subtitle2 == null &&
          bodyText1 == null && bodyText2 == null) ||
         (display4 == null && display3 == null && display2 == null && display1 == null && headline == null && title == null &&
          subhead == null && subtitle == null &&
183 184 185
          body2 == null && body1 == null),
         'Cannot mix 2014 and 2018 terms in call to TextTheme() constructor.',
       ),
186 187 188 189 190 191 192 193 194 195
       headline1 = headline1 ?? display4,
       headline2 = headline2 ?? display3,
       headline3 = headline3 ?? display2,
       headline4 = headline4 ?? display1,
       headline5 = headline5 ?? headline,
       headline6 = headline6 ?? title,
       subtitle1 = subtitle1 ?? subhead,
       subtitle2 = subtitle2 ?? subtitle,
       bodyText1 = bodyText1 ?? body2,
       bodyText2 = bodyText2 ?? body1;
196 197

  /// Extremely large text.
198
  final TextStyle? headline1;
199 200 201 202

  /// Very, very large text.
  ///
  /// Used for the date in the dialog shown by [showDatePicker].
203
  final TextStyle? headline2;
204 205

  /// Very large text.
206
  final TextStyle? headline3;
207 208

  /// Large text.
209
  final TextStyle? headline4;
210 211 212

  /// Used for large text in dialogs (e.g., the month and year in the dialog
  /// shown by [showDatePicker]).
213
  final TextStyle? headline5;
214 215 216

  /// Used for the primary text in app bars and dialogs (e.g., [AppBar.title]
  /// and [AlertDialog.title]).
217
  final TextStyle? headline6;
218 219

  /// Used for the primary text in lists (e.g., [ListTile.title]).
220
  final TextStyle? subtitle1;
221

222
  /// For medium emphasis text that's a little smaller than [subtitle1].
223
  final TextStyle? subtitle2;
224 225

  /// Used for emphasizing text that would otherwise be [bodyText2].
226
  final TextStyle? bodyText1;
227

228
  /// The default text style for [Material].
229
  final TextStyle? bodyText2;
230 231

  /// Used for auxiliary text associated with images.
232
  final TextStyle? caption;
233

234
  /// Used for text on [ElevatedButton], [TextButton] and [OutlinedButton].
235
  final TextStyle? button;
236

237
  /// The smallest style.
238 239
  ///
  /// Typically used for captions or to introduce a (larger) headline.
240
  final TextStyle? overline;
241

242 243 244 245 246 247
  /// Extremely large text.
  ///
  /// This was the name used in the material design 2014 specification. The new
  /// specification calls this [headline1].
  @Deprecated(
    'This is the term used in the 2014 version of material design. The modern term is headline1. '
248
    'This feature was deprecated after v1.13.8.',
249
  )
250
  TextStyle? get display4 => headline1;
251 252 253 254 255 256 257

  /// Very, very large text.
  ///
  /// This was the name used in the material design 2014 specification. The new
  /// specification calls this [headline2].
  @Deprecated(
    'This is the term used in the 2014 version of material design. The modern term is headline2. '
258
    'This feature was deprecated after v1.13.8.',
259
  )
260
  TextStyle? get display3 => headline2;
261 262 263 264 265 266 267

  /// Very large text.
  ///
  /// This was the name used in the material design 2014 specification. The new
  /// specification calls this [headline3].
  @Deprecated(
    'This is the term used in the 2014 version of material design. The modern term is headline3. '
268
    'This feature was deprecated after v1.13.8.',
269
  )
270
  TextStyle? get display2 => headline3;
271 272 273 274 275 276 277

  /// Large text.
  ///
  /// This was the name used in the material design 2014 specification. The new
  /// specification calls this [headline4].
  @Deprecated(
    'This is the term used in the 2014 version of material design. The modern term is headline4. '
278
    'This feature was deprecated after v1.13.8.',
279
  )
280
  TextStyle? get display1 => headline4;
281 282 283 284 285 286 287

  /// Used for large text in dialogs.
  ///
  /// This was the name used in the material design 2014 specification. The new
  /// specification calls this [headline5].
  @Deprecated(
    'This is the term used in the 2014 version of material design. The modern term is headline5. '
288
    'This feature was deprecated after v1.13.8.',
289
  )
290
  TextStyle? get headline => headline5;
291 292 293 294 295 296 297

  /// Used for the primary text in app bars and dialogs.
  ///
  /// This was the name used in the material design 2014 specification. The new
  /// specification calls this [headline6].
  @Deprecated(
    'This is the term used in the 2014 version of material design. The modern term is headline6. '
298
    'This feature was deprecated after v1.13.8.',
299
  )
300
  TextStyle? get title => headline6;
301 302 303 304 305 306 307

  /// Used for the primary text in lists (e.g., [ListTile.title]).
  ///
  /// This was the name used in the material design 2014 specification. The new
  /// specification calls this [subtitle1].
  @Deprecated(
    'This is the term used in the 2014 version of material design. The modern term is subtitle1. '
308
    'This feature was deprecated after v1.13.8.',
309
  )
310
  TextStyle? get subhead => subtitle1;
311 312 313 314 315 316 317

  /// For medium emphasis text that's a little smaller than [subhead].
  ///
  /// This was the name used in the material design 2014 specification. The new
  /// specification calls this [subtitle2].
  @Deprecated(
    'This is the term used in the 2014 version of material design. The modern term is subtitle2. '
318
    'This feature was deprecated after v1.13.8.',
319
  )
320
  TextStyle? get subtitle => subtitle2;
321 322 323 324 325

  /// Used for emphasizing text that would otherwise be [body1].
  ///
  /// This was the name used in the material design 2014 specification. The new
  /// specification calls this `body1`, and it is exposed in this API as
326
  /// [bodyText1].
327 328
  @Deprecated(
    'This is the term used in the 2014 version of material design. The modern term is bodyText1. '
329
    'This feature was deprecated after v1.13.8.',
330
  )
331
  TextStyle? get body2 => bodyText1;
332 333 334 335 336

  /// Used for the default text style for [Material].
  ///
  /// This was the name used in the material design 2014 specification. The new
  /// specification calls this `body2`, and it is exposed in this API as
337
  /// [bodyText2].
338
  @Deprecated(
339
    'This is the term used in the 2014 version of material design. The modern term is bodyText2. '
340
    'This feature was deprecated after v1.13.8.',
341
  )
342
  TextStyle? get body1 => bodyText2;
343 344


345 346 347 348 349 350 351
  /// Creates a copy of this text theme but with the given fields replaced with
  /// the new values.
  ///
  /// Consider using [Typography.black] or [Typography.white], which implement
  /// the typography styles in the material design specification, as a starting
  /// point.
  ///
352
  /// {@tool snippet}
353 354 355 356 357
  ///
  /// ```dart
  /// /// A Widget that sets the ambient theme's title text color for its
  /// /// descendants, while leaving other ambient theme attributes alone.
  /// class TitleColorThemeCopy extends StatelessWidget {
358
  ///   const TitleColorThemeCopy({Key? key, required this.child, required this.titleColor}) : super(key: key);
359 360 361 362 363 364 365 366 367 368
  ///
  ///   final Color titleColor;
  ///   final Widget child;
  ///
  ///   @override
  ///   Widget build(BuildContext context) {
  ///     final ThemeData theme = Theme.of(context);
  ///     return Theme(
  ///       data: theme.copyWith(
  ///         textTheme: theme.textTheme.copyWith(
369
  ///           headline6: theme.textTheme.headline6!.copyWith(
370 371 372 373 374 375 376 377 378
  ///             color: titleColor,
  ///           ),
  ///         ),
  ///       ),
  ///       child: child,
  ///     );
  ///   }
  /// }
  /// ```
379
  /// {@end-tool}
380 381 382
  ///
  /// See also:
  ///
383 384
  ///  * [merge] is used instead of [copyWith] when you want to merge all
  ///    of the fields of a TextTheme instead of individual fields.
385
  TextTheme copyWith({
386 387 388 389 390 391 392 393 394 395 396 397 398
    TextStyle? headline1,
    TextStyle? headline2,
    TextStyle? headline3,
    TextStyle? headline4,
    TextStyle? headline5,
    TextStyle? headline6,
    TextStyle? subtitle1,
    TextStyle? subtitle2,
    TextStyle? bodyText1,
    TextStyle? bodyText2,
    TextStyle? caption,
    TextStyle? button,
    TextStyle? overline,
399 400
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline1. '
401
      'This feature was deprecated after v1.13.8.',
402
    )
403
    TextStyle? display4,
404 405
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline2. '
406
      'This feature was deprecated after v1.13.8.',
407
    )
408
    TextStyle? display3,
409 410
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline3. '
411
      'This feature was deprecated after v1.13.8.',
412
    )
413
    TextStyle? display2,
414 415
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline4. '
416
      'This feature was deprecated after v1.13.8.',
417
    )
418
    TextStyle? display1,
419 420
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline5. '
421
      'This feature was deprecated after v1.13.8.',
422
    )
423
    TextStyle? headline,
424 425
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline6. '
426
      'This feature was deprecated after v1.13.8.',
427
    )
428
    TextStyle? title,
429 430
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is subtitle1. '
431
      'This feature was deprecated after v1.13.8.',
432
    )
433
    TextStyle? subhead,
434 435
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is subtitle2. '
436
      'This feature was deprecated after v1.13.8.',
437
    )
438
    TextStyle? subtitle,
439 440
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is bodyText1. '
441
      'This feature was deprecated after v1.13.8.',
442
    )
443
    TextStyle? body2,
444 445
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is bodyText2. '
446
      'This feature was deprecated after v1.13.8.',
447
    )
448
    TextStyle? body1,
449
  }) {
450 451 452 453 454 455
    assert(
      (headline1 == null && headline2 == null && headline3 == null && headline4 == null && headline5 == null && headline6 == null &&
       subtitle1 == null && subtitle2 == null &&
       bodyText1 == null && bodyText2 == null) ||
      (display4 == null && display3 == null && display2 == null && display1 == null && headline == null && title == null &&
       subhead == null && subtitle == null &&
456 457 458
       body2 == null && body1 == null),
      'Cannot mix 2014 and 2018 terms in call to TextTheme.copyWith().',
    );
459
    return TextTheme(
460 461 462 463 464 465 466 467 468 469
      headline1: headline1 ?? display4 ?? this.headline1,
      headline2: headline2 ?? display3 ?? this.headline2,
      headline3: headline3 ?? display2 ?? this.headline3,
      headline4: headline4 ?? display1 ?? this.headline4,
      headline5: headline5 ?? headline ?? this.headline5,
      headline6: headline6 ?? title ?? this.headline6,
      subtitle1: subtitle1 ?? subhead ?? this.subtitle1,
      subtitle2: subtitle2 ?? subtitle ?? this.subtitle2,
      bodyText1: bodyText1 ?? body2 ?? this.bodyText1,
      bodyText2: bodyText2 ?? body1 ?? this.bodyText2,
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
      caption: caption ?? this.caption,
      button: button ?? this.button,
      overline: overline ?? this.overline,
    );
  }

  /// Creates a new [TextTheme] where each text style from this object has been
  /// merged with the matching text style from the `other` object.
  ///
  /// The merging is done by calling [TextStyle.merge] on each respective pair
  /// of text styles from this and the [other] text themes and is subject to
  /// the value of [TextStyle.inherit] flag. For more details, see the
  /// documentation on [TextStyle.merge] and [TextStyle.inherit].
  ///
  /// If this theme, or the `other` theme has members that are null, then the
  /// non-null one (if any) is used. If the `other` theme is itself null, then
  /// this [TextTheme] is returned unchanged. If values in both are set, then
  /// the values are merged using [TextStyle.merge].
  ///
  /// This is particularly useful if one [TextTheme] defines one set of
  /// properties and another defines a different set, e.g. having colors
  /// defined in one text theme and font sizes in another, or when one
  /// [TextTheme] has only some fields defined, and you want to define the rest
  /// by merging it with a default theme.
  ///
495
  /// {@tool snippet}
496 497 498 499 500
  ///
  /// ```dart
  /// /// A Widget that sets the ambient theme's title text color for its
  /// /// descendants, while leaving other ambient theme attributes alone.
  /// class TitleColorTheme extends StatelessWidget {
501
  ///   const TitleColorTheme({Key? key, required this.child, required this.titleColor}) : super(key: key);
502 503 504 505 506 507 508 509 510 511 512 513
  ///
  ///   final Color titleColor;
  ///   final Widget child;
  ///
  ///   @override
  ///   Widget build(BuildContext context) {
  ///     ThemeData theme = Theme.of(context);
  ///     // This partialTheme is incomplete: it only has the title style
  ///     // defined. Just replacing theme.textTheme with partialTheme would
  ///     // set the title, but everything else would be null. This isn't very
  ///     // useful, so merge it with the existing theme to keep all of the
  ///     // preexisting definitions for the other styles.
514
  ///     final TextTheme partialTheme = TextTheme(headline6: TextStyle(color: titleColor));
515 516 517 518 519
  ///     theme = theme.copyWith(textTheme: theme.textTheme.merge(partialTheme));
  ///     return Theme(data: theme, child: child);
  ///   }
  /// }
  /// ```
520
  /// {@end-tool}
521 522 523
  ///
  /// See also:
  ///
524 525 526
  ///  * [copyWith] is used instead of [merge] when you wish to override
  ///    individual fields in the [TextTheme] instead of merging all of the
  ///    fields of two [TextTheme]s.
527
  TextTheme merge(TextTheme? other) {
528 529 530
    if (other == null)
      return this;
    return copyWith(
531 532 533 534 535 536 537 538 539 540
      headline1: headline1?.merge(other.headline1) ?? other.headline1,
      headline2: headline2?.merge(other.headline2) ?? other.headline2,
      headline3: headline3?.merge(other.headline3) ?? other.headline3,
      headline4: headline4?.merge(other.headline4) ?? other.headline4,
      headline5: headline5?.merge(other.headline5) ?? other.headline5,
      headline6: headline6?.merge(other.headline6) ?? other.headline6,
      subtitle1: subtitle1?.merge(other.subtitle1) ?? other.subtitle1,
      subtitle2: subtitle2?.merge(other.subtitle2) ?? other.subtitle2,
      bodyText1: bodyText1?.merge(other.bodyText1) ?? other.bodyText1,
      bodyText2: bodyText2?.merge(other.bodyText2) ?? other.bodyText2,
541 542 543 544 545 546 547 548 549
      caption: caption?.merge(other.caption) ?? other.caption,
      button: button?.merge(other.button) ?? other.button,
      overline: overline?.merge(other.overline) ?? other.overline,
    );
  }

  /// Creates a copy of this text theme but with the given field replaced in
  /// each of the individual text styles.
  ///
550 551
  /// The `displayColor` is applied to [headline4], [headline3], [headline2],
  /// [headline1], and [caption]. The `bodyColor` is applied to the remaining
552 553 554 555 556 557
  /// text styles.
  ///
  /// Consider using [Typography.black] or [Typography.white], which implement
  /// the typography styles in the material design specification, as a starting
  /// point.
  TextTheme apply({
558
    String? fontFamily,
559 560
    double fontSizeFactor = 1.0,
    double fontSizeDelta = 0.0,
561 562 563 564 565
    Color? displayColor,
    Color? bodyColor,
    TextDecoration? decoration,
    Color? decorationColor,
    TextDecorationStyle? decorationStyle,
566 567
  }) {
    return TextTheme(
568
      headline1: headline1?.apply(
569 570 571 572 573 574 575 576
        color: displayColor,
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
577
      headline2: headline2?.apply(
578 579 580 581 582 583 584 585
        color: displayColor,
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
586
      headline3: headline3?.apply(
587 588 589 590 591 592 593 594
        color: displayColor,
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
595
      headline4: headline4?.apply(
596 597 598 599 600 601 602 603
        color: displayColor,
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
604
      headline5: headline5?.apply(
605
        color: bodyColor,
606 607 608 609 610 611 612
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
613
      headline6: headline6?.apply(
614
        color: bodyColor,
615 616 617 618 619 620 621
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
622
      subtitle1: subtitle1?.apply(
623
        color: bodyColor,
624 625 626 627 628 629 630
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
631
      subtitle2: subtitle2?.apply(
632
        color: bodyColor,
633 634 635 636 637 638 639
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
640
      bodyText1: bodyText1?.apply(
641
        color: bodyColor,
642 643 644 645 646 647 648
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
649 650
      bodyText2: bodyText2?.apply(
        color: bodyColor,
651 652 653 654 655 656 657
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
658 659
      caption: caption?.apply(
        color: displayColor,
660 661 662 663 664 665 666
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
667
      button: button?.apply(
668 669 670 671 672 673 674 675
        color: bodyColor,
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
676
      overline: overline?.apply(
677 678 679 680 681 682 683 684 685 686 687 688 689
        color: bodyColor,
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
    );
  }

  /// Linearly interpolate between two text themes.
  ///
690
  /// {@macro dart.ui.shadow.lerp}
691
  static TextTheme lerp(TextTheme? a, TextTheme? b, double t) {
692 693
    assert(t != null);
    return TextTheme(
694 695 696 697 698 699 700 701 702 703
      headline1: TextStyle.lerp(a?.headline1, b?.headline1, t),
      headline2: TextStyle.lerp(a?.headline2, b?.headline2, t),
      headline3: TextStyle.lerp(a?.headline3, b?.headline3, t),
      headline4: TextStyle.lerp(a?.headline4, b?.headline4, t),
      headline5: TextStyle.lerp(a?.headline5, b?.headline5, t),
      headline6: TextStyle.lerp(a?.headline6, b?.headline6, t),
      subtitle1: TextStyle.lerp(a?.subtitle1, b?.subtitle1, t),
      subtitle2: TextStyle.lerp(a?.subtitle2, b?.subtitle2, t),
      bodyText1: TextStyle.lerp(a?.bodyText1, b?.bodyText1, t),
      bodyText2: TextStyle.lerp(a?.bodyText2, b?.bodyText2, t),
704 705 706
      caption: TextStyle.lerp(a?.caption, b?.caption, t),
      button: TextStyle.lerp(a?.button, b?.button, t),
      overline: TextStyle.lerp(a?.overline, b?.overline, t),
707 708 709 710
    );
  }

  @override
711
  bool operator ==(Object other) {
712 713 714 715
    if (identical(this, other))
      return true;
    if (other.runtimeType != runtimeType)
      return false;
716
    return other is TextTheme
717 718 719 720 721 722 723 724 725 726 727 728 729
      && headline1 == other.headline1
      && headline2 == other.headline2
      && headline3 == other.headline3
      && headline4 == other.headline4
      && headline5 == other.headline5
      && headline6 == other.headline6
      && subtitle1 == other.subtitle1
      && subtitle2 == other.subtitle2
      && bodyText1 == other.bodyText1
      && bodyText2 == other.bodyText2
      && caption == other.caption
      && button == other.button
      && overline == other.overline;
730 731 732 733 734 735
  }

  @override
  int get hashCode {
    // The hashValues() function supports up to 20 arguments.
    return hashValues(
736 737 738 739 740 741 742 743 744 745
      headline1,
      headline2,
      headline3,
      headline4,
      headline5,
      headline6,
      subtitle1,
      subtitle2,
      bodyText1,
      bodyText2,
746 747 748 749 750 751 752 753 754
      caption,
      button,
      overline,
    );
  }

  @override
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
755 756 757 758 759 760 761 762 763 764 765
    final TextTheme defaultTheme = Typography.material2018(platform: defaultTargetPlatform).black;
    properties.add(DiagnosticsProperty<TextStyle>('headline1', headline1, defaultValue: defaultTheme.headline1));
    properties.add(DiagnosticsProperty<TextStyle>('headline2', headline2, defaultValue: defaultTheme.headline2));
    properties.add(DiagnosticsProperty<TextStyle>('headline3', headline3, defaultValue: defaultTheme.headline3));
    properties.add(DiagnosticsProperty<TextStyle>('headline4', headline4, defaultValue: defaultTheme.headline4));
    properties.add(DiagnosticsProperty<TextStyle>('headline5', headline5, defaultValue: defaultTheme.headline5));
    properties.add(DiagnosticsProperty<TextStyle>('headline6', headline6, defaultValue: defaultTheme.headline6));
    properties.add(DiagnosticsProperty<TextStyle>('subtitle1', subtitle1, defaultValue: defaultTheme.subtitle1));
    properties.add(DiagnosticsProperty<TextStyle>('subtitle2', subtitle2, defaultValue: defaultTheme.subtitle2));
    properties.add(DiagnosticsProperty<TextStyle>('bodyText1', bodyText1, defaultValue: defaultTheme.bodyText1));
    properties.add(DiagnosticsProperty<TextStyle>('bodyText2', bodyText2, defaultValue: defaultTheme.bodyText2));
766 767 768 769 770
    properties.add(DiagnosticsProperty<TextStyle>('caption', caption, defaultValue: defaultTheme.caption));
    properties.add(DiagnosticsProperty<TextStyle>('button', button, defaultValue: defaultTheme.button));
    properties.add(DiagnosticsProperty<TextStyle>('overline', overline, defaultValue: defaultTheme.overline));
  }
}