Rich and selectable text
Two special cases of text: a paragraph made of pieces with different styles ( RichText ) and text the reader can select and copy ( SelectableText ). Plain text is Text .
RichText
One paragraph made of several pieces, each with its own style: a bold word in the middle of a phrase, a colored amount in a line. The pieces wrap together, as one line of text — unlike a
Row
of several
Text
elements.
Type:
multi-child
RichText
Text "Charged "
Text "€12.50"
#style fontWeight:bold color:0xFF4F46E5
Text " for the subscription"
Every child is a
Text
: its positional argument is the text of the piece,
#style
is the style of the piece. Other parameters of the child are not read, and for a child that is not a
Text
its first argument is taken as the text.
| Parameter | Type | Default | Description |
|---|---|---|---|
#style
|
TextStyle | — |
Common style of all pieces; a piece's own style adds to it and overrides it. Pieces without their own
textTransform
inherit it from the common style
|
textAlign
|
string | start |
Line alignment:
start
,
end
,
left
,
right
,
center
,
justify
|
maxLines
|
int | — | Maximum number of lines |
overflow
|
string | clip |
What happens to text that does not fit in
maxLines
:
clip
,
ellipsis
,
fade
,
visible
|
softWrap
|
bool | true | Whether lines wrap at the available width |
textDirection
|
string | — |
ltr
or
rtl
|
The style fields (
fontSize
,
fontWeight
,
color
,
fontStyle
,
textTransform
…) are the same as in
Text
.
RichText textAlign:center maxLines:2 overflow:ellipsis
#style fontSize:14 color:0xFF374151
Text "By pressing the button you accept the "
Text "terms"
#style fontWeight:bold
Text " and the "
Text "privacy policy"
#style fontStyle:italic
SelectableText
Text that can be selected and copied: an order number, a code, an address.
Type:
leaf
SelectableText "ORD-2041-77"
#style fontSize:18 fontWeight:bold
| Parameter | Type | Default | Description |
|---|---|---|---|
| (positional) | string | — | The text |
data
|
string | — | Same as the positional argument |
#style
|
TextStyle | — | Text style — as in Text |
textAlign
|
string | start | Line alignment |
maxLines
|
int | — | Maximum number of lines |
textScaleFactor
|
double | — | Text size multiplier for this element |
showCursor
|
bool | false | Show the cursor while selecting |
cursorWidth
|
double | 2 | Cursor width |
cursorColor
|
color | — | Cursor color |
cursorRadius
|
double | — | Cursor corner radius |
Differences between the app and the site
-
RichTexton the site is a block ofspanpieces; the style of each piece carries over. Of the common#styleonlytextTransformreaches the site; its other fields (fontSize,color…) do not carry over — if you need them on the site too, write them in the#styleof each piece.maxLines,overflow,softWrap,textDirectionare not read on the site;textAlignis. -
SelectableTexton the site is built like a plain Text : page text is selectable anyway. Large bold text may become a heading (h1…), as withText.maxLines,textScaleFactorand the cursor parameters are not read. Text given throughdata:is not shown on the site (an emptyspan) — write it as the positional argument.