TextTheme class
Material design text theme.
Definitions for the various typographical styles found in Material Design (e.g., labelLarge, bodySmall). Rather than creating a TextTheme directly, you can obtain an instance as Typography.black or Typography.white.
To obtain the current text theme, call TextTheme.of with the current BuildContext. This is equivalent to calling Theme.of and reading the ThemeData.textTheme property.
The names of the TextTheme properties match this table from the Material Design spec.
The Material Design typography scheme was significantly changed in the current (2021) version of the specification (https://m3.material.io/styles/typography/tokens).
The 2021 spec has fifteen text styles:
NAME | SIZE | HEIGHT | WEIGHT | SPACING | |
---|---|---|---|---|---|
displayLarge | 57.0 | 64.0 | regular | -0.25 | |
displayMedium | 45.0 | 52.0 | regular | 0.0 | |
displaySmall | 36.0 | 44.0 | regular | 0.0 | |
headlineLarge | 32.0 | 40.0 | regular | 0.0 | |
headlineMedium | 28.0 | 36.0 | regular | 0.0 | |
headlineSmall | 24.0 | 32.0 | regular | 0.0 | |
titleLarge | 22.0 | 28.0 | regular | 0.0 | |
titleMedium | 16.0 | 24.0 | medium | 0.15 | |
titleSmall | 14.0 | 20.0 | medium | 0.1 | |
bodyLarge | 16.0 | 24.0 | regular | 0.5 | |
bodyMedium | 14.0 | 20.0 | regular | 0.25 | |
bodySmall | 12.0 | 16.0 | regular | 0.4 | |
labelLarge | 14.0 | 20.0 | medium | 0.1 | |
labelMedium | 12.0 | 16.0 | medium | 0.5 | |
labelSmall | 11.0 | 16.0 | medium | 0.5 |
...where "regular" is FontWeight.w400
and "medium" is FontWeight.w500
.
The names of the 2018 TextTheme properties match this table from the Material Design spec with a few exceptions: the styles called H1-H6 in the spec are displayLarge-titleLarge in the API chart, body1,body2 are called bodyLarge and bodyMedium, caption is now bodySmall, button is labelLarge, and overline is now labelSmall.
The 2018 spec has thirteen text styles:
NAME | SIZE | WEIGHT | SPACING | |
---|---|---|---|---|
displayLarge | 96.0 | light | -1.5 | |
displayMedium | 60.0 | light | -0.5 | |
displaySmall | 48.0 | regular | 0.0 | |
headlineMedium | 34.0 | regular | 0.25 | |
headlineSmall | 24.0 | regular | 0.0 | |
titleLarge | 20.0 | medium | 0.15 | |
titleMedium | 16.0 | regular | 0.15 | |
titleSmall | 14.0 | medium | 0.1 | |
bodyLarge | 16.0 | regular | 0.5 | |
bodyMedium | 14.0 | regular | 0.25 | |
bodySmall | 12.0 | regular | 0.4 | |
labelLarge | 14.0 | medium | 1.25 | |
labelSmall | 10.0 | regular | 1.5 |
...where "light" is FontWeight.w300
, "regular" is FontWeight.w400
and
"medium" is FontWeight.w500
.
By default, text styles are initialized to match the 2018 Material Design specification as listed above. To provide backwards compatibility, the 2014 specification is also available.
To explicitly configure a Theme for the 2018 sizes, weights, and letter spacings, you can initialize its ThemeData.typography value using Typography.material2018. The Typography constructor defaults to this configuration. To configure a Theme for the 2014 sizes, weights, and letter spacings, initialize its ThemeData.typography value using Typography.material2014.
See also:
- Typography, the class that generates TextThemes appropriate for a platform.
- Theme, for other aspects of a Material Design application that can be globally adjusted, such as the color scheme.
- material.io/design/typography/
- Mixed-in types
- Annotations
Constructors
- TextTheme({TextStyle? displayLarge, TextStyle? displayMedium, TextStyle? displaySmall, TextStyle? headlineLarge, TextStyle? headlineMedium, TextStyle? headlineSmall, TextStyle? titleLarge, TextStyle? titleMedium, TextStyle? titleSmall, TextStyle? bodyLarge, TextStyle? bodyMedium, TextStyle? bodySmall, TextStyle? labelLarge, TextStyle? labelMedium, TextStyle? labelSmall})
-
Creates a text theme that uses the given values.
const
Properties
- bodyLarge → TextStyle?
-
Largest of the body styles.
final
- bodyMedium → TextStyle?
-
Middle size of the body styles.
final
- bodySmall → TextStyle?
-
Smallest of the body styles.
final
- displayLarge → TextStyle?
-
Largest of the display styles.
final
- displayMedium → TextStyle?
-
Middle size of the display styles.
final
- displaySmall → TextStyle?
-
Smallest of the display styles.
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- headlineLarge → TextStyle?
-
Largest of the headline styles.
final
- headlineMedium → TextStyle?
-
Middle size of the headline styles.
final
- headlineSmall → TextStyle?
-
Smallest of the headline styles.
final
- labelLarge → TextStyle?
-
Largest of the label styles.
final
- labelMedium → TextStyle?
-
Middle size of the label styles.
final
- labelSmall → TextStyle?
-
Smallest of the label styles.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- titleLarge → TextStyle?
-
Largest of the title styles.
final
- titleMedium → TextStyle?
-
Middle size of the title styles.
final
- titleSmall → TextStyle?
-
Smallest of the title styles.
final
Methods
-
apply(
{String? fontFamily, List< String> ? fontFamilyFallback, String? package, double fontSizeFactor = 1.0, double fontSizeDelta = 0.0, Color? displayColor, Color? bodyColor, TextDecoration? decoration, Color? decorationColor, TextDecorationStyle? decorationStyle}) → TextTheme - Creates a copy of this text theme but with the given field replaced in each of the individual text styles.
-
copyWith(
{TextStyle? displayLarge, TextStyle? displayMedium, TextStyle? displaySmall, TextStyle? headlineLarge, TextStyle? headlineMedium, TextStyle? headlineSmall, TextStyle? titleLarge, TextStyle? titleMedium, TextStyle? titleSmall, TextStyle? bodyLarge, TextStyle? bodyMedium, TextStyle? bodySmall, TextStyle? labelLarge, TextStyle? labelMedium, TextStyle? labelSmall}) → TextTheme - Creates a copy of this text theme but with the given fields replaced with the new values.
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
override
-
merge(
TextTheme? other) → TextTheme -
Creates a new TextTheme where each text style from this object has been
merged with the matching text style from the
other
object. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringShort(
) → String -
A brief description of this object, usually just the runtimeType and the
hashCode.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override
Static Methods
-
lerp(
TextTheme? a, TextTheme? b, double t) → TextTheme - Linearly interpolate between two text themes.
-
of(
BuildContext context) → TextTheme - The ThemeData.textTheme property of the ambient Theme.
-
primaryOf(
BuildContext context) → TextTheme - The ThemeData.primaryTextTheme property of the ambient Theme.