TextComponentStyle class Styling

Defines the visual style for a text component, including color, background, font styles, and spacing (padding/margin).

A TextComponentStyle encapsulates all styling information that determines how text is displayed in a terminal or canvas-based UI, using ANSI color codes and text formatting attributes.

Styling Options

  • Foreground/Background Colors: Controlled by color and bgColor using AnsiColorType.
  • Font Styles: Bold, italic, underline, strikethrough, etc., using FontStyle.
  • Padding & Margin: Controlled via EdgeInsets for layout spacing.

Example

final style = TextComponentStyle(
  color: Colors.red,
  bgColor: ColorRGB(0, 0, 0),
  styles: {FontStyle.bold, FontStyle.underline},
  padding: EdgeInsets.all(1),
  margin: EdgeInsets.symmetric(horizontal: 2),
);

final boldStyle = style.bold().foreground(Colors.blue);

See Also

Constructors

TextComponentStyle({AnsiColorType? color, AnsiColorType? bgColor, Set<FontStyle>? styles, EdgeInsets padding = const EdgeInsets.all(0), EdgeInsets margin = const EdgeInsets.all(0)})
Creates a TextComponentStyle with optional color, background color, font styles, and padding/margin settings.
const

Properties

bgColor → AnsiColorType?
The background text color.
final
color → AnsiColorType?
The foreground text color.
final
hashCode → int
The hash code for this object.
no setterinherited
horizontalMargin → int
The total horizontal margin (left + right).
no setter
horizontalPadding → int
The total horizontal padding (left + right).
no setter
margin → EdgeInsets
The space outside the text boundaries.
final
padding → EdgeInsets
The space inside the text boundaries.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
styles → Set<FontStyle>
The set of font styles (e.g., bold, italic, underline).
final
verticalMargin → int
The total vertical margin (top + bottom).
no setter
verticalPadding → int
The total vertical padding (top + bottom).
no setter

Methods

background(AnsiColorType color) → TextComponentStyle
Returns a copy of this style with the given bgColor as the background color.
bold() → TextComponentStyle
Returns a copy of this style with bold text enabled.
copyWith({AnsiColorType? color, AnsiColorType? bgColor, Set<FontStyle>? styles, EdgeInsets? padding, EdgeInsets? margin}) → TextComponentStyle
Returns a new TextComponentStyle with the given properties overridden.
foreground(AnsiColorType color) → TextComponentStyle
Returns a copy of this style with the given color as the foreground color.
getStyleAnsi() → String
Builds and returns the ANSI style code string for this style.
italic() → TextComponentStyle
Returns a copy of this style with italic text enabled.
marginOnly({int top = 0, int right = 0, int bottom = 0, int left = 0}) → TextComponentStyle
Returns a copy of this style with updated margin values.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
paddingOnly({int top = 0, int right = 0, int bottom = 0, int left = 0}) → TextComponentStyle
Returns a copy of this style with updated padding values.
strikethrough() → TextComponentStyle
Returns a copy of this style with strikethrough text enabled.
toString() → String
A string representation of this object.
inherited
underline() → TextComponentStyle
Returns a copy of this style with underlined text enabled.

Operators

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