Skip to main content

Text

Displays a string of text with a single style.

Basic Usage

widgets.Text{
Content: "Hello, Drift",
Style: graphics.TextStyle{Color: colors.OnSurface, FontSize: 16},
}

Properties

PropertyTypeDescription
ContentstringText to display
Stylegraphics.TextStyleFont size, color, weight, and other styling
Aligngraphics.TextAlignHorizontal text alignment (only applies when text wraps)
MaxLinesintMaximum number of visible lines (0 = unlimited)
Wrapgraphics.TextWrapText wrapping behavior (default wraps at constraint width)

Using Text Themes

Read typography styles from the current theme for consistent sizing and weight:

textTheme := theme.TextThemeOf(ctx)

widgets.Text{Content: "Headline", Style: textTheme.HeadlineLarge}
widgets.Text{Content: "Body text", Style: textTheme.BodyLarge}
widgets.Text{Content: "Caption", Style: textTheme.BodySmall}

Common Patterns

Styled Text

widgets.Text{
Content: "Important",
Style: graphics.TextStyle{
Color: colors.Primary,
FontSize: 18,
FontWeight: graphics.FontWeightBold,
},
}

Text in a Layout

widgets.Column{
MainAxisSize: widgets.MainAxisSizeMin,
Children: []core.Widget{
widgets.Text{Content: title, Style: textTheme.TitleMedium},
widgets.VSpace(4),
widgets.Text{Content: subtitle, Style: textTheme.BodySmall},
},
}
  • Icon for rendering text glyphs as icons
  • Theming for typography configuration