Text class

A widget that renders styled text with optional wrapping.

It supports standard formatting, custom maximum lines, and alignment. In compliance with terminal standards, it correctly measures string width using measureStringWidth which handles CJK (Chinese, Japanese, Korean) and Emoji characters that occupy two visual columns (wide characters).

Example Usage

Text(
  'This is some multi-column CJK text: 漢字',
  style: Style(foreground: Color(0xFFFFCC00)),
  wrap: true,
  textAlign: TextAlign.center,
);

Properties and Settings

Property Type Description
data String The text characters to render.
style Style Formatting attributes (bold, dim, underline, color).
wrap bool Wrap words to a new line when constraints are exceeded.
textAlign TextAlign Alignment option (left, center, right, justify).
maxLines int? Optional maximum height limits.
Inheritance

Constructors

Text(String data, {Style style = Style.empty, bool wrap = true, TextAlign textAlign = TextAlign.left, int? maxLines})
Creates a Text widget to render styled text.
const

Properties

data String
The text characters to render.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
The optional key for this widget.
finalinherited
maxLines int?
Optional maximum height limits.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
style Style
Formatting attributes (bold, dim, underline, color).
final
textAlign TextAlign
Alignment option (left, center, right, justify).
final
wrap bool
Wrap words to a new line when constraints are exceeded.
final

Methods

createElement() Element
Creates an Element to manage this widget's location in the tree.
inherited
getIntrinsicHeight(int width) int
Computes the intrinsic height of this widget under the given width constraint.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
render(Buffer buffer, Rect area) → void
Renders the widget onto the provided buffer within the specified area.
override
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited