pub struct TextTheme {Show 15 fields
pub display_large: Option<TextStyle>,
pub display_medium: Option<TextStyle>,
pub display_small: Option<TextStyle>,
pub headline_large: Option<TextStyle>,
pub headline_medium: Option<TextStyle>,
pub headline_small: Option<TextStyle>,
pub title_large: Option<TextStyle>,
pub title_medium: Option<TextStyle>,
pub title_small: Option<TextStyle>,
pub body_large: Option<TextStyle>,
pub body_medium: Option<TextStyle>,
pub body_small: Option<TextStyle>,
pub label_large: Option<TextStyle>,
pub label_medium: Option<TextStyle>,
pub label_small: Option<TextStyle>,
}Expand description
Material design text theme.
Definitions for the various typographical styles found in Material Design
(e.g., label_large, body_small). 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.text_theme 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 generatesTextThemes appropriate for a platform.Theme, for other aspects of a Material Design application that can be globally adjusted, such as the color scheme.- https://material.io/design/typography/
Fields§
§display_large: Option<TextStyle>Largest of the display styles.
As the largest text on the screen, display styles are reserved for short, important text or numerals. They work best on large screens.
display_medium: Option<TextStyle>Middle size of the display styles.
As the largest text on the screen, display styles are reserved for short, important text or numerals. They work best on large screens.
display_small: Option<TextStyle>Smallest of the display styles.
As the largest text on the screen, display styles are reserved for short, important text or numerals. They work best on large screens.
headline_large: Option<TextStyle>Largest of the headline styles.
Headline styles are smaller than display styles. They’re best-suited for short, high-emphasis text on smaller screens.
headline_medium: Option<TextStyle>Middle size of the headline styles.
Headline styles are smaller than display styles. They’re best-suited for short, high-emphasis text on smaller screens.
headline_small: Option<TextStyle>Smallest of the headline styles.
Headline styles are smaller than display styles. They’re best-suited for short, high-emphasis text on smaller screens.
title_large: Option<TextStyle>Largest of the title styles.
Titles are smaller than headline styles and should be used for shorter, medium-emphasis text.
title_medium: Option<TextStyle>Middle size of the title styles.
Titles are smaller than headline styles and should be used for shorter, medium-emphasis text.
title_small: Option<TextStyle>Smallest of the title styles.
Titles are smaller than headline styles and should be used for shorter, medium-emphasis text.
body_large: Option<TextStyle>Largest of the body styles.
Body styles are used for longer passages of text.
body_medium: Option<TextStyle>Middle size of the body styles.
Body styles are used for longer passages of text.
The default text style for Material.
body_small: Option<TextStyle>Smallest of the body styles.
Body styles are used for longer passages of text.
label_large: Option<TextStyle>Largest of the label styles.
Label styles are smaller, utilitarian styles, used for areas of the UI such as text inside of components or very small supporting text in the content body, like captions.
Used for text on ElevatedButton, TextButton and OutlinedButton.
label_medium: Option<TextStyle>Middle size of the label styles.
Label styles are smaller, utilitarian styles, used for areas of the UI such as text inside of components or very small supporting text in the content body, like captions.
label_small: Option<TextStyle>Smallest of the label styles.
Label styles are smaller, utilitarian styles, used for areas of the UI such as text inside of components or very small supporting text in the content body, like captions.
Implementations§
Source§impl TextTheme
impl TextTheme
Sourcepub fn new() -> TextTheme
pub fn new() -> TextTheme
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:
https://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 copy_with or
apply.
The 2018 styles cannot be mixed with the 2021 styles. Only one or the other is allowed in this constructor. The 2018 styles are deprecated and will eventually be removed.
Sourcepub fn display_large(self, display_large: TextStyle) -> TextTheme
pub fn display_large(self, display_large: TextStyle) -> TextTheme
Dart TextTheme(displayLarge:).
Sourcepub fn display_medium(self, display_medium: TextStyle) -> TextTheme
pub fn display_medium(self, display_medium: TextStyle) -> TextTheme
Dart TextTheme(displayMedium:).
Sourcepub fn display_small(self, display_small: TextStyle) -> TextTheme
pub fn display_small(self, display_small: TextStyle) -> TextTheme
Dart TextTheme(displaySmall:).
Sourcepub fn headline_large(self, headline_large: TextStyle) -> TextTheme
pub fn headline_large(self, headline_large: TextStyle) -> TextTheme
Dart TextTheme(headlineLarge:).
Sourcepub fn headline_medium(self, headline_medium: TextStyle) -> TextTheme
pub fn headline_medium(self, headline_medium: TextStyle) -> TextTheme
Dart TextTheme(headlineMedium:).
Sourcepub fn headline_small(self, headline_small: TextStyle) -> TextTheme
pub fn headline_small(self, headline_small: TextStyle) -> TextTheme
Dart TextTheme(headlineSmall:).
Sourcepub fn title_large(self, title_large: TextStyle) -> TextTheme
pub fn title_large(self, title_large: TextStyle) -> TextTheme
Dart TextTheme(titleLarge:).
Sourcepub fn title_medium(self, title_medium: TextStyle) -> TextTheme
pub fn title_medium(self, title_medium: TextStyle) -> TextTheme
Dart TextTheme(titleMedium:).
Sourcepub fn title_small(self, title_small: TextStyle) -> TextTheme
pub fn title_small(self, title_small: TextStyle) -> TextTheme
Dart TextTheme(titleSmall:).
Sourcepub fn body_large(self, body_large: TextStyle) -> TextTheme
pub fn body_large(self, body_large: TextStyle) -> TextTheme
Dart TextTheme(bodyLarge:).
Sourcepub fn body_medium(self, body_medium: TextStyle) -> TextTheme
pub fn body_medium(self, body_medium: TextStyle) -> TextTheme
Dart TextTheme(bodyMedium:).
Sourcepub fn body_small(self, body_small: TextStyle) -> TextTheme
pub fn body_small(self, body_small: TextStyle) -> TextTheme
Dart TextTheme(bodySmall:).
Sourcepub fn label_large(self, label_large: TextStyle) -> TextTheme
pub fn label_large(self, label_large: TextStyle) -> TextTheme
Dart TextTheme(labelLarge:).
Sourcepub fn label_medium(self, label_medium: TextStyle) -> TextTheme
pub fn label_medium(self, label_medium: TextStyle) -> TextTheme
Dart TextTheme(labelMedium:).
Sourcepub fn label_small(self, label_small: TextStyle) -> TextTheme
pub fn label_small(self, label_small: TextStyle) -> TextTheme
Dart TextTheme(labelSmall:).
Sourcepub fn copy_with(&self) -> TextTheme
pub fn copy_with(&self) -> TextTheme
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.
Dart’s named arguments are the setters on the copy:
theme.copy_with().title_large(style).
See also:
Sourcepub fn merge(&self, other: Option<&TextTheme>) -> TextTheme
pub fn merge(&self, other: Option<&TextTheme>) -> TextTheme
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.
See also:
Sourcepub fn apply(&self) -> TextThemeApply<'_>
pub fn apply(&self) -> TextThemeApply<'_>
Creates a copy of this text theme but with the given field replaced in each of the individual text styles.
The display_color is applied to display_large,
display_medium, display_small,
headline_large, headline_medium,
and body_small. The body_color is applied to the remaining
text styles.
Consider using Typography.black or Typography.white, which implement
the typography styles in the Material Design specification, as a starting
point.
Chain the named arguments, then TextThemeApply::into_text_theme;
theme.apply() with no further setters is Dart apply() with defaults.
Sourcepub fn lerp(a: Option<&TextTheme>, b: Option<&TextTheme>, t: f64) -> TextTheme
pub fn lerp(a: Option<&TextTheme>, b: Option<&TextTheme>, t: f64) -> TextTheme
Linearly interpolate between two text themes.
{@macro dart.ui.shadow.lerp}
Sourcepub fn of(app: &mut App, context: BuildContext) -> TextTheme
pub fn of(app: &mut App, context: BuildContext) -> TextTheme
The ThemeData.text_theme property of the ambient Theme.
Equivalent to Theme::of(app, context).text_theme.
See also:
TextTheme::primary_of, which returns theThemeData.primary_text_themeproperty of the ambientThemeinstead.
Sourcepub fn primary_of(app: &mut App, context: BuildContext) -> TextTheme
pub fn primary_of(app: &mut App, context: BuildContext) -> TextTheme
The ThemeData.primary_text_theme property of the ambient Theme.
Equivalent to Theme::of(app, context).primary_text_theme.
See also:
TextTheme::of, which returns theThemeData.text_themeproperty of the ambientThemeinstead.
Trait Implementations§
Source§impl Diagnosticable for TextTheme
impl Diagnosticable for TextTheme
Source§fn debug_fill_properties(&self, properties: &mut DiagnosticPropertiesBuilder)
fn debug_fill_properties(&self, properties: &mut DiagnosticPropertiesBuilder)
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
Object.runtimeType as diagnostics print it: the last segment of
the Rust type path, without generic arguments.Source§fn identity_hash(&self) -> u64
fn identity_hash(&self) -> u64
Object.hashCode as diagnostics print it: the object’s address.Source§fn to_string_short(&self) -> String
fn to_string_short(&self) -> String
Source§fn to_diagnostics_node(&self) -> DiagnosticableNode
fn to_diagnostics_node(&self) -> DiagnosticableNode
DiagnosticsNode::to_string_deep.Source§fn to_diagnostics_node_with(
&self,
name: Option<String>,
style: Option<DiagnosticsTreeStyle>,
) -> DiagnosticableNode
fn to_diagnostics_node_with( &self, name: Option<String>, style: Option<DiagnosticsTreeStyle>, ) -> DiagnosticableNode
toDiagnosticsNode(name:, style:).Source§fn to_string(&self) -> String
fn to_string(&self) -> String
toString: a single-line description with properties and no
children. Read moreSource§fn to_string_at(&self, min_level: DiagnosticLevel) -> String
fn to_string_at(&self, min_level: DiagnosticLevel) -> String
toString(minLevel:).