text_theme.dart 29.4 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 129 130
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline1. '
      'This feature was deprecated after v1.13.8.'
    )
131
    TextStyle? display4,
132 133 134 135
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline2. '
      'This feature was deprecated after v1.13.8.'
    )
136
    TextStyle? display3,
137 138 139 140
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline3. '
      'This feature was deprecated after v1.13.8.'
    )
141
    TextStyle? display2,
142 143 144 145
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline4. '
      'This feature was deprecated after v1.13.8.'
    )
146
    TextStyle? display1,
147 148 149 150
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline5. '
      'This feature was deprecated after v1.13.8.'
    )
151
    TextStyle? headline,
152 153 154 155
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline6. '
      'This feature was deprecated after v1.13.8.'
    )
156
    TextStyle? title,
157 158 159 160
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is subtitle1. '
      'This feature was deprecated after v1.13.8.'
    )
161
    TextStyle? subhead,
162 163 164 165
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is subtitle2. '
      'This feature was deprecated after v1.13.8.'
    )
166
    TextStyle? subtitle,
167 168 169 170
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is bodyText1. '
      'This feature was deprecated after v1.13.8.'
    )
171
    TextStyle? body2,
172 173 174 175
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is bodyText2. '
      'This feature was deprecated after v1.13.8.'
    )
176
    TextStyle? body1,
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
  }) : 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 &&
          body2 == null && body1 == null), 'Cannot mix 2014 and 2018 terms in call to TextTheme() constructor.'),
       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;
194 195

  /// Extremely large text.
196
  final TextStyle? headline1;
197 198 199 200

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

  /// Very large text.
204
  final TextStyle? headline3;
205 206

  /// Large text.
207
  final TextStyle? headline4;
208 209 210

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

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

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

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

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

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

  /// Used for auxiliary text associated with images.
230
  final TextStyle? caption;
231

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

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

240 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. '
    'This feature was deprecated after v1.13.8.'
  )
248
  TextStyle? get display4 => headline1;
249 250 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. '
    'This feature was deprecated after v1.13.8.'
  )
258
  TextStyle? get display3 => headline2;
259 260 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. '
    'This feature was deprecated after v1.13.8.'
  )
268
  TextStyle? get display2 => headline3;
269 270 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. '
    'This feature was deprecated after v1.13.8.'
  )
278
  TextStyle? get display1 => headline4;
279 280 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. '
    'This feature was deprecated after v1.13.8.'
  )
288
  TextStyle? get headline => headline5;
289 290 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. '
    'This feature was deprecated after v1.13.8.'
  )
298
  TextStyle? get title => headline6;
299 300 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. '
    'This feature was deprecated after v1.13.8.'
  )
308
  TextStyle? get subhead => subtitle1;
309 310 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. '
    'This feature was deprecated after v1.13.8.'
  )
318
  TextStyle? get subtitle => subtitle2;
319 320 321 322 323

  /// 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
324
  /// [bodyText1].
325 326 327 328
  @Deprecated(
    'This is the term used in the 2014 version of material design. The modern term is bodyText1. '
    'This feature was deprecated after v1.13.8.'
  )
329
  TextStyle? get body2 => bodyText1;
330 331 332 333 334

  /// 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
335
  /// [bodyText2].
336
  @Deprecated(
337
    'This is the term used in the 2014 version of material design. The modern term is bodyText2. '
338 339
    'This feature was deprecated after v1.13.8.'
  )
340
  TextStyle? get body1 => bodyText2;
341 342


343 344 345 346 347 348 349
  /// 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.
  ///
350
  /// {@tool snippet}
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
  ///
  /// ```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 {
  ///   TitleColorThemeCopy({Key key, this.child, this.titleColor}) : super(key: key);
  ///
  ///   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(
367
  ///           headline6: theme.textTheme.headline6.copyWith(
368 369 370 371 372 373 374 375 376
  ///             color: titleColor,
  ///           ),
  ///         ),
  ///       ),
  ///       child: child,
  ///     );
  ///   }
  /// }
  /// ```
377
  /// {@end-tool}
378 379 380
  ///
  /// See also:
  ///
381 382
  ///  * [merge] is used instead of [copyWith] when you want to merge all
  ///    of the fields of a TextTheme instead of individual fields.
383
  TextTheme copyWith({
384 385 386 387 388 389 390 391 392 393 394 395 396
    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,
397 398 399 400
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline1. '
      'This feature was deprecated after v1.13.8.'
    )
401
    TextStyle? display4,
402 403 404 405
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline2. '
      'This feature was deprecated after v1.13.8.'
    )
406
    TextStyle? display3,
407 408 409 410
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline3. '
      'This feature was deprecated after v1.13.8.'
    )
411
    TextStyle? display2,
412 413 414 415
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline4. '
      'This feature was deprecated after v1.13.8.'
    )
416
    TextStyle? display1,
417 418 419 420
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline5. '
      'This feature was deprecated after v1.13.8.'
    )
421
    TextStyle? headline,
422 423 424 425
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is headline6. '
      'This feature was deprecated after v1.13.8.'
    )
426
    TextStyle? title,
427 428 429 430
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is subtitle1. '
      'This feature was deprecated after v1.13.8.'
    )
431
    TextStyle? subhead,
432 433 434 435
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is subtitle2. '
      'This feature was deprecated after v1.13.8.'
    )
436
    TextStyle? subtitle,
437 438 439 440
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is bodyText1. '
      'This feature was deprecated after v1.13.8.'
    )
441
    TextStyle? body2,
442 443 444 445
    @Deprecated(
      'This is the term used in the 2014 version of material design. The modern term is bodyText2. '
      'This feature was deprecated after v1.13.8.'
    )
446
    TextStyle? body1,
447
  }) {
448 449 450 451 452 453 454
    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 &&
       body2 == null && body1 == null), 'Cannot mix 2014 and 2018 terms in call to TextTheme.copyWith().');
455
    return TextTheme(
456 457 458 459 460 461 462 463 464 465
      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,
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
      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.
  ///
491
  /// {@tool snippet}
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
  ///
  /// ```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 {
  ///   TitleColorTheme({Key key, this.child, this.titleColor}) : super(key: key);
  ///
  ///   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.
510
  ///     TextTheme partialTheme = TextTheme(headline6: TextStyle(color: titleColor));
511 512 513 514 515
  ///     theme = theme.copyWith(textTheme: theme.textTheme.merge(partialTheme));
  ///     return Theme(data: theme, child: child);
  ///   }
  /// }
  /// ```
516
  /// {@end-tool}
517 518 519
  ///
  /// See also:
  ///
520 521 522
  ///  * [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.
523
  TextTheme merge(TextTheme? other) {
524 525 526
    if (other == null)
      return this;
    return copyWith(
527 528 529 530 531 532 533 534 535 536
      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,
537 538 539 540 541 542 543 544 545
      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.
  ///
546 547
  /// The `displayColor` is applied to [headline4], [headline3], [headline2],
  /// [headline1], and [caption]. The `bodyColor` is applied to the remaining
548 549 550 551 552 553
  /// 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({
554
    String? fontFamily,
555 556
    double fontSizeFactor = 1.0,
    double fontSizeDelta = 0.0,
557 558 559 560 561
    Color? displayColor,
    Color? bodyColor,
    TextDecoration? decoration,
    Color? decorationColor,
    TextDecorationStyle? decorationStyle,
562 563
  }) {
    return TextTheme(
564
      headline1: headline1?.apply(
565 566 567 568 569 570 571 572
        color: displayColor,
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
573
      headline2: headline2?.apply(
574 575 576 577 578 579 580 581
        color: displayColor,
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
582
      headline3: headline3?.apply(
583 584 585 586 587 588 589 590
        color: displayColor,
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
591
      headline4: headline4?.apply(
592 593 594 595 596 597 598 599
        color: displayColor,
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
600
      headline5: headline5?.apply(
601
        color: bodyColor,
602 603 604 605 606 607 608
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
609
      headline6: headline6?.apply(
610
        color: bodyColor,
611 612 613 614 615 616 617
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
618
      subtitle1: subtitle1?.apply(
619
        color: bodyColor,
620 621 622 623 624 625 626
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
627
      subtitle2: subtitle2?.apply(
628
        color: bodyColor,
629 630 631 632 633 634 635
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
636
      bodyText1: bodyText1?.apply(
637
        color: bodyColor,
638 639 640 641 642 643 644
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
645 646
      bodyText2: bodyText2?.apply(
        color: bodyColor,
647 648 649 650 651 652 653
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
654 655
      caption: caption?.apply(
        color: displayColor,
656 657 658 659 660 661 662
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
663
      button: button?.apply(
664 665 666 667 668 669 670 671
        color: bodyColor,
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
672
      overline: overline?.apply(
673 674 675 676 677 678 679 680 681 682 683 684 685
        color: bodyColor,
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        fontFamily: fontFamily,
        fontSizeFactor: fontSizeFactor,
        fontSizeDelta: fontSizeDelta,
      ),
    );
  }

  /// Linearly interpolate between two text themes.
  ///
686
  /// {@macro dart.ui.shadow.lerp}
687
  static TextTheme lerp(TextTheme? a, TextTheme? b, double t) {
688 689
    assert(t != null);
    return TextTheme(
690 691 692 693 694 695 696 697 698 699
      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),
700 701 702
      caption: TextStyle.lerp(a?.caption, b?.caption, t),
      button: TextStyle.lerp(a?.button, b?.button, t),
      overline: TextStyle.lerp(a?.overline, b?.overline, t),
703 704 705 706
    );
  }

  @override
707
  bool operator ==(Object other) {
708 709 710 711
    if (identical(this, other))
      return true;
    if (other.runtimeType != runtimeType)
      return false;
712
    return other is TextTheme
713 714 715 716 717 718 719 720 721 722 723 724 725
      && 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;
726 727 728 729 730 731
  }

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

  @override
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
751 752 753 754 755 756 757 758 759 760 761
    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));
762 763 764 765 766
    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));
  }
}