Skip to main content

TextTheme

Struct TextTheme 

Source
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:

NAMESIZEHEIGHTWEIGHTSPACING
displayLarge57.064.0regular-0.25
displayMedium45.052.0regular0.0
displaySmall36.044.0regular0.0
headlineLarge32.040.0regular0.0
headlineMedium28.036.0regular0.0
headlineSmall24.032.0regular0.0
titleLarge22.028.0regular0.0
titleMedium16.024.0medium0.15
titleSmall14.020.0medium0.1
bodyLarge16.024.0regular0.5
bodyMedium14.020.0regular0.25
bodySmall12.016.0regular0.4
labelLarge14.020.0medium0.1
labelMedium12.016.0medium0.5
labelSmall11.016.0medium0.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:

NAMESIZEWEIGHTSPACING
displayLarge96.0light-1.5
displayMedium60.0light-0.5
displaySmall48.0regular0.0
headlineMedium34.0regular0.25
headlineSmall24.0regular0.0
titleLarge20.0medium0.15
titleMedium16.0regular0.15
titleSmall14.0medium0.1
bodyLarge16.0regular0.5
bodyMedium14.0regular0.25
bodySmall12.0regular0.4
labelLarge14.0medium1.25
labelSmall10.0regular1.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:

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

Source

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.

Source

pub fn display_large(self, display_large: TextStyle) -> TextTheme

Dart TextTheme(displayLarge:).

Source

pub fn display_medium(self, display_medium: TextStyle) -> TextTheme

Dart TextTheme(displayMedium:).

Source

pub fn display_small(self, display_small: TextStyle) -> TextTheme

Dart TextTheme(displaySmall:).

Source

pub fn headline_large(self, headline_large: TextStyle) -> TextTheme

Dart TextTheme(headlineLarge:).

Source

pub fn headline_medium(self, headline_medium: TextStyle) -> TextTheme

Dart TextTheme(headlineMedium:).

Source

pub fn headline_small(self, headline_small: TextStyle) -> TextTheme

Dart TextTheme(headlineSmall:).

Source

pub fn title_large(self, title_large: TextStyle) -> TextTheme

Dart TextTheme(titleLarge:).

Source

pub fn title_medium(self, title_medium: TextStyle) -> TextTheme

Dart TextTheme(titleMedium:).

Source

pub fn title_small(self, title_small: TextStyle) -> TextTheme

Dart TextTheme(titleSmall:).

Source

pub fn body_large(self, body_large: TextStyle) -> TextTheme

Dart TextTheme(bodyLarge:).

Source

pub fn body_medium(self, body_medium: TextStyle) -> TextTheme

Dart TextTheme(bodyMedium:).

Source

pub fn body_small(self, body_small: TextStyle) -> TextTheme

Dart TextTheme(bodySmall:).

Source

pub fn label_large(self, label_large: TextStyle) -> TextTheme

Dart TextTheme(labelLarge:).

Source

pub fn label_medium(self, label_medium: TextStyle) -> TextTheme

Dart TextTheme(labelMedium:).

Source

pub fn label_small(self, label_small: TextStyle) -> TextTheme

Dart TextTheme(labelSmall:).

Source

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:

  • merge is used instead of copy_with when you want to merge all of the fields of a TextTheme instead of individual fields.
Source

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:

Source

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.

Source

pub fn lerp(a: Option<&TextTheme>, b: Option<&TextTheme>, t: f64) -> TextTheme

Linearly interpolate between two text themes.

{@macro dart.ui.shadow.lerp}

Source

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 the ThemeData.primary_text_theme property of the ambient Theme instead.
Source

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 the ThemeData.text_theme property of the ambient Theme instead.

Trait Implementations§

Source§

impl Clone for TextTheme

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TextTheme

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TextTheme

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Diagnosticable for TextTheme

Source§

fn debug_fill_properties(&self, properties: &mut DiagnosticPropertiesBuilder)

Add additional properties associated with the node.
Source§

fn type_name(&self) -> &'static str

Dart’s Object.runtimeType as diagnostics print it: the last segment of the Rust type path, without generic arguments.
Source§

fn identity_hash(&self) -> u64

Dart’s Object.hashCode as diagnostics print it: the object’s address.
Source§

fn to_string_short(&self) -> String

A brief description of this object, usually just the type and the hash.
Source§

fn to_diagnostics_node(&self) -> DiagnosticableNode

Returns a debug representation of the object used by debugging tools and by DiagnosticsNode::to_string_deep.
Source§

fn to_diagnostics_node_with( &self, name: Option<String>, style: Option<DiagnosticsTreeStyle>, ) -> DiagnosticableNode

Dart toDiagnosticsNode(name:, style:).
Source§

fn to_string(&self) -> String

Dart’s toString: a single-line description with properties and no children. Read more
Source§

fn to_string_at(&self, min_level: DiagnosticLevel) -> String

Dart’s toString(minLevel:).
Source§

impl Display for TextTheme

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<TextThemeApply<'_>> for TextTheme

Source§

fn from(apply: TextThemeApply<'_>) -> TextTheme

Converts to this type from the input type.
Source§

impl PartialEq for TextTheme

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TextTheme

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>