TextSpan class

An immutable span of text that can hold styling overrides and nested child spans.

Under standard terminal styling, TextSpan represents a hierarchical tree node that propagates formatting rules (color, bold, underline, etc.) to all descendants. Any child TextSpan overrides specific properties while inheriting the remaining styles.

Example

const TextSpan(
  style: Style(foreground: CharmColors.pepper),
  children: [
    TextSpan(text: 'This is red and normal '),
    TextSpan(
      text: 'bold text',
      style: Style(modifiers: Modifier.bold),
    ),
  ],
)

Constructors

TextSpan({String? text, Style? style, List<TextSpan> children = const []})
Initializes a text span with optional text content, styling overrides, and nested children spans.
const

Properties

children List<TextSpan>
Nested child text spans that inherit styling from this node.
final
hashCode int
The hash code for this object.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
style Style?
Style overrides applied to this span and its children.
final
text String?
The literal text represented by this span. Can be null if this span only hosts children.
final

Methods

buildStyledChars(List<StyledChar> output, Style parentStyle) → void
Recursively flattens the styling tree into a list of styled characters.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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