Text
Displays text content with support for styles, alignment and wrapping.
Type:
leaf
Text "Hello, World!"
Parameters
| Parameter | Type | Description |
|---|---|---|
| (positional 0) | string | The text to display |
textAlign
|
string |
Text alignment:
left
,
right
,
center
,
justify
,
start
,
end
|
direction
|
string |
Text direction:
ltr
,
rtl
|
overflow
|
string |
Behavior on overflow:
clip
,
fade
,
ellipsis
,
visible
|
softWrap
|
bool | Allow line wrapping |
maxLines
|
int | Maximum number of lines |
textWidthBasis
|
string |
Text width basis:
parent
,
longestLine
|
selectionColor
|
color | Text selection color |
semanticsLabel
|
string | Label for accessibility |
semanticsIdentifier
|
string | Identifier for accessibility |
Nested structures
#style
The text style.
Text "Heading"
#style fontSize:24 fontWeight:bold color:#FFFFFF
Outline instead of fill
strokeWidth:
draws the letters as an OUTLINE — a technique for a giant chapter number or a word behind the content. The outline color comes from
strokeColor:
, and without it from
color:
.
Text "03"
#style fontFamily:"Anton" fontSize:320 strokeWidth:1.5 color:0x1FFAFAFF
The outline is ADDED to the fill — just as
-webkit-text-stroke
is added to
color
in web layout. An outline without a fill is a transparent
color:
, exactly as in a style sheet. When both are visible, the fill is drawn first, then the outline — in the same order as the browser's
paint-order
.
Digits of equal width —
fontFeatures
fontFeatures:["tnum"]
turns on tabular figures: every digit takes the same space, and a ticking timer or counter does not push its neighbors. The list holds four-letter OpenType tags (
"tnum"
,
"lnum"
,
"smcp"
…).
State @mmss:"04:27"
Text $mmss
#style fontSize:22 fontWeight:w700 fontFeatures:["tnum"]
On the site this is
font-feature-settings
, in the app —
FontFeature
on
TextStyle
. It works only if the font contains such figures (system fonts and most web fonts do).
Case by style, not by string
textTransform:
(
uppercase
/
lowercase
/
none
) raises or lowers the case of the LABEL without touching the text itself.
Text $strings.chapterLabel
#style fontSize:12 letterSpacing:2.16 textTransform:uppercase
Why not
{upperCase(...)}
: the function changes the string, and on the site the capitals end up in THE DOCUMENT ITSELF — search on the page stops finding the word in its normal spelling, copying gives shouting, and a screen reader spells it letter by letter. The style changes only the rendering.
On the site this is CSS
text-transform
. In the app the label is drawn in the required case, while the screen reader gets the original string — the same look, correct pronunciation.
It works on
Text
,
SelectableText
and
RichText
(where it is inherited by spans, as in CSS). A
#style
given to a widget that owns its own string (a field label, a
Chip
) does NOT change the case — the same in the app and on the site.
capitalize
is deliberately not supported: the browser raises the first letter of a word by Unicode word boundaries (
x-ray
→
X-Ray
), the app cannot do that, and one markup would give two different texts.
Examples
Text with a variable (template string)
State @userName:"Anna"
Text $"Hello, ${userName}!"
Styled text
Text "Section heading"
#style fontSize:32 fontWeight:bold color:#FFFFFF
Text with a line limit
Text "A very long description..." maxLines:2 overflow:ellipsis
Text in context
Column spacing:8
Text "Heading"
#style fontSize:24 fontWeight:bold
Text "Subheading"
#style fontSize:16 color:#888888