An immutable style in which paint text.

Sample code

Bold

Here, a single line of text in a Text widget is given a specific style override. The style is mixed with the ambient DefaultTextStyle by the Text widget.

new Text(
  'No, we need bold strokes. We need this plan.',
  style: new TextStyle(fontWeight: FontWeight.bold),
)

Italics

As in the previous example, the Text widget is given a specific style override which is implicitly mixed with the ambient DefaultTextStyle.

new Text(
  'Welcome to the present, we\'re running a real nation.',
  style: new TextStyle(fontStyle: FontStyle.italic),
)

Opacity

Each line here is progressively more opaque. The base color is Colors.black, and Color.withOpacity is used to create a derivative color with the desired opacity. The root TextSpan for this RichText widget is explicitly given the ambient DefaultTextStyle, since RichText does not do that automatically. The inner TextStyle objects are implicitly mixed with the parent TextSpan's TextSpan.style.

new RichText(
  text: new TextSpan(
    style: DefaultTextStyle.of(context).style,
    children: <TextSpan>[
      new TextSpan(
        text: 'You don\'t have the votes.\n',
        style: new TextStyle(color: Colors.black.withOpacity(0.6)),
      ),
      new TextSpan(
        text: 'You don\'t have the votes!\n',
        style: new TextStyle(color: Colors.black.withOpacity(0.8)),
      ),
      new TextSpan(
        text: 'You\'re gonna need congressional approval and you don\'t have the votes!\n',
        style: new TextStyle(color: Colors.black.withOpacity(1.0)),
      ),
    ],
  ),
)

Size

In this example, the ambient DefaultTextStyle is explicitly manipulated to obtain a TextStyle that doubles the default font size.

new Text(
  'These are wise words, enterprising men quote \'em.',
  style: DefaultTextStyle.of(context).style.apply(fontSizeFactor: 2.0),
)

Line height

The height property can be used to change the line height. Here, the line height is set to 100 logical pixels, so that the text is very spaced out.

new Text(
  'Don\'t act surprised, you guys, cuz I wrote \'em!',
  style: new TextStyle(height: 100.0),
)

Wavy red underline with black text

Styles can be combined. In this example, the misspelt word is drawn in black text and underlined with a wavy red line to indicate a spelling error. (The remainder is styled according to the Flutter default text styles, not the ambient DefaultTextStyle, since no explicit style is given and RichText does not automatically use the ambient DefaultTextStyle.)

new RichText(
  text: new TextSpan(
    text: 'Don\'t tax the South ',
    children: <TextSpan>[
      new TextSpan(
        text: 'cuz',
        style: new TextStyle(
          color: Colors.black,
          decoration: TextDecoration.underline,
          decorationColor: Colors.red,
          decorationStyle: TextDecorationStyle.wavy,
        ),
      ),
      new TextSpan(
        text: ' we got it made in the shade',
      ),
    ],
  ),
)

See also:

Annotations
  • @immutable

Constructors

TextStyle({bool inherit: true, Color color, String fontFamily, double fontSize, FontWeight fontWeight, FontStyle fontStyle, double letterSpacing, double wordSpacing, TextBaseline textBaseline, double height, TextDecoration decoration, Color decorationColor, TextDecorationStyle decorationStyle })
Creates a text style.
const

Properties

color Color
The color to use when painting the text.
final
decoration TextDecoration
The decorations to paint near the text (e.g., an underline).
final
decorationColor Color
The color in which to paint the text decorations.
final
decorationStyle TextDecorationStyle
The style in which to paint the text decorations (e.g., dashed).
final
fontFamily String
The name of the font to use when painting the text (e.g., Roboto).
final
fontSize double
The size of glyphs (in logical pixels) to use when painting the text. [...]
final
fontStyle FontStyle
The typeface variant to use when drawing the letters (e.g., italics).
final
fontWeight FontWeight
The typeface thickness to use when painting the text (e.g., bold).
final
hashCode int
@override, read-only
height double
The height of this text span, as a multiple of the font size. [...]
final
inherit bool
Whether null values are replaced with their value in an ancestor text style (e.g., in a TextSpan tree). [...]
final
letterSpacing double
The amount of space (in logical pixels) to add between each letter. A negative value can be used to bring the letters closer.
final
textBaseline TextBaseline
The common baseline that should be aligned between this text span and its parent text span, or, for the root text spans, with the line box.
final
wordSpacing double
The amount of space (in logical pixels) to add at each sequence of white-space (i.e. between each word). A negative value can be used to bring the words closer.
final
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

apply({Color color, String fontFamily, double fontSizeFactor: 1.0, double fontSizeDelta: 0.0, int fontWeightDelta: 0, double letterSpacingFactor: 1.0, double letterSpacingDelta: 0.0, double wordSpacingFactor: 1.0, double wordSpacingDelta: 0.0, double heightFactor: 1.0, double heightDelta: 0.0 }) TextStyle
Creates a copy of this text style but with the numeric fields multiplied by the given factors and then incremented by the given deltas. [...]
copyWith({Color color, String fontFamily, double fontSize, FontWeight fontWeight, FontStyle fontStyle, double letterSpacing, double wordSpacing, TextBaseline textBaseline, double height, TextDecoration decoration, Color decorationColor, TextDecorationStyle decorationStyle }) TextStyle
Creates a copy of this text style but with the given fields replaced with the new values.
getParagraphStyle({TextAlign textAlign, double textScaleFactor: 1.0, String ellipsis, int maxLines }) ParagraphStyle
The style information for paragraphs, encoded for use by dart:ui. [...]
getTextStyle({double textScaleFactor: 1.0 }) TextStyle
The style information for text runs, encoded for use by dart:ui.
merge(TextStyle other) TextStyle
Returns a new text style that matches this text style but with some values replaced by the non-null parameters of the given text style. If the given text style is null, simply returns this text style.
toString([String prefix = '' ]) String
Returns a string representation of this object.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited

Operators

operator ==(other) bool
The equality operator. [...]

Static Methods

lerp(TextStyle begin, TextStyle end, double t) TextStyle
Interpolate between two text styles. [...]