TextTheme constructor Null safety

const TextTheme(
  1. {TextStyle? displayLarge,
  2. TextStyle? displayMedium,
  3. TextStyle? displaySmall,
  4. TextStyle? headlineLarge,
  5. TextStyle? headlineMedium,
  6. TextStyle? headlineSmall,
  7. TextStyle? titleLarge,
  8. TextStyle? titleMedium,
  9. TextStyle? titleSmall,
  10. TextStyle? bodyLarge,
  11. TextStyle? bodyMedium,
  12. TextStyle? bodySmall,
  13. TextStyle? labelLarge,
  14. TextStyle? labelMedium,
  15. TextStyle? labelSmall,
  16. TextStyle? headline1,
  17. TextStyle? headline2,
  18. TextStyle? headline3,
  19. TextStyle? headline4,
  20. TextStyle? headline5,
  21. TextStyle? headline6,
  22. TextStyle? subtitle1,
  23. TextStyle? subtitle2,
  24. TextStyle? bodyText1,
  25. TextStyle? bodyText2,
  26. TextStyle? caption,
  27. TextStyle? button,
  28. TextStyle? overline}
)

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:

material.io/design/typography/#type-scale

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.

Please note that you can not mix and match the 2018 styles with the 2021 styles. Only one or the other is allowed in this constructor. The 2018 styles will be deprecated and removed eventually.

Implementation

const TextTheme({
  TextStyle? displayLarge,
  TextStyle? displayMedium,
  TextStyle? displaySmall,
  this.headlineLarge,
  TextStyle? headlineMedium,
  TextStyle? headlineSmall,
  TextStyle? titleLarge,
  TextStyle? titleMedium,
  TextStyle? titleSmall,
  TextStyle? bodyLarge,
  TextStyle? bodyMedium,
  TextStyle? bodySmall,
  TextStyle? labelLarge,
  this.labelMedium,
  TextStyle? labelSmall,
  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,
}) : assert(
       (displayLarge == null && displayMedium == null && displaySmall == null && headlineMedium == null &&
           headlineSmall == null && titleLarge == null && titleMedium == null && titleSmall == null &&
           bodyLarge == null && bodyMedium == null && bodySmall == null && labelLarge == null && labelSmall == null) ||
       (headline1 == null && headline2 == null && headline3 == null && headline4 == null &&
           headline5 == null && headline6 == null && subtitle1 == null && subtitle2 == null &&
           bodyText1 == null && bodyText2 == null && caption == null && button == null && overline == null),
       'Cannot mix 2018 and 2021 terms in call to TextTheme() constructor.'
     ),
     displayLarge = displayLarge ?? headline1,
     displayMedium = displayMedium ?? headline2,
     displaySmall = displaySmall ?? headline3,
     headlineMedium = headlineMedium ?? headline4,
     headlineSmall = headlineSmall ?? headline5,
     titleLarge = titleLarge ?? headline6,
     titleMedium = titleMedium ?? subtitle1,
     titleSmall = titleSmall ?? subtitle2,
     bodyLarge = bodyLarge ?? bodyText1,
     bodyMedium = bodyMedium ?? bodyText2,
     bodySmall = bodySmall ?? caption,
     labelLarge = labelLarge ?? button,
     labelSmall = labelSmall ?? overline;