Text
Display text with styling options
Renders a string. Set type with font; see Font for the named styles and Font.custom.
Methods
Text(content, options?)WidgetNodeRenders a string.
- content String required
The string to render.
- options Any
- font RootlessFont
Size, weight, family and design as one value.
- color Color
Text colour.
- textAlign TextAlign
A TextAlign, for alignment inside the available width.
- maxLines Number
Truncate beyond this many lines.
- overflow TextOverflow
A TextOverflow, for how truncation looks. Needs maxLines.
- lineSpacing Number
Extra points between lines.
- font RootlessFont
Text.timer(endsAt, options?)WidgetNodeA clock that keeps counting without a timeline reload. Counts down to endsAt (epoch seconds, a DateTime, or a Date), or up once it has passed. Use this for anything live, a widget only redraws every few minutes.
- endsAt Any required
A DateTime, a Date, or epoch seconds. Counts down to it, and up once it has passed.
- options Any
- font RootlessFont
Size, weight, family and design as one value.
- color Color
Text colour.
- textAlign TextAlign
A TextAlign, for alignment inside the available width.
- maxLines Number
Truncate beyond this many lines.
- overflow TextOverflow
A TextOverflow, for how truncation looks. Needs maxLines.
- lineSpacing Number
Extra points between lines.
- font RootlessFont
Text.measure(text, options?)AnyHow big this string will be. Pair with Widget.size rather than guessing whether text fits.
- text String required
The string to measure.
- options Any
- font RootlessFont
The font it will be drawn in. Left out, the system font at 14 points.
- maxWidth Number
The width it has to fit in.
- maxLines Number
The line budget, for
fits.
- font RootlessFont
returns { width, height, lines, lineHeight, fits }. fits is false when the string needs more lines than maxLines allows.
Examples
Styled text
Text("Hello World", {
color: Color.white(),
font: Font.system(24, FontWeight.bold),
textAlign: "center"
})