Table class

A fluent builder for creating styled tables.

Provides a chainable API for table configuration with support for per-cell conditional styling via styleFunc.

final table = Table()
    .headers(['Name', 'Status', 'Age'])
    .row(['Alice', 'Active', '25'])
    .row(['Bob', 'Inactive', '30'])
    .styleFunc((row, col, data) {
      if (row == Table.headerRow) {
        return Style().bold().foreground(Colors.cyan);
      }
      if (col == 1 && data == 'Active') {
        return Style().foreground(Colors.success);
      }
      return null;
    })
    .border(style_border.Border.rounded)
    .render();

print(table);

A component for rendering styled tables.

The Table component provides a fluent API for building tables with:

  • Headers and data rows.
  • Custom borders (rounded, ascii, etc.).
  • Per-cell styling via TableStyleFunc.
  • Automatic column width calculation.

Example:

final table = Table()
  .headers(['ID', 'Name'])
  .rows([
    ['1', 'Alice'],
    ['2', 'Bob'],
  ])
  .border(Border.rounded);

print(table.render());
Inheritance
Available extensions

Constructors

Table({RenderConfig renderConfig = const RenderConfig()})
Creates a new empty table builder.

Properties

hashCode int
The hash code for this object.
no setterinherited
lineCount int
Returns the number of lines in the rendered table.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

baseStyle(Style style) Table
Sets the base style for the whole table.
border(Border border) Table
Sets the border style.
borderBottom(bool value) Table
Sets whether to show the bottom border.
borderColumn(bool value) Table
Sets whether to show column separators.
borderHeader(bool value) Table
Sets whether to show the header separator.
borderLeft(bool value) Table
Sets whether to show the left border.
borderRight(bool value) Table
Sets whether to show the right border.
borderRow(bool value) Table
Sets whether to show row separators.
borderStyle(Style style) Table
Sets the style for the table borders.
borderTop(bool value) Table
Sets whether to show the top border.
cellStyle(Style style) Table
Sets the default cell style.
clearRows() Table
Clears all rows from the table.
headers(List<String> headers) Table
Sets the table headers.
headerStyle(Style style) Table
Sets the style for the header row.
height(int value) Table
Sets the table height (limits visible rows).
init() Cmd?
Returns an optional command to execute on program startup.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
offset(int value) Table
Sets the row offset (skips first N rows).
padding(int value) Table
Sets the cell padding.
render() String
Renders the table to a string.
override
row(List<Object?> cells) Table
Adds a row to the table.
rows(List<List<Object?>> rows) Table
Adds multiple rows to the table.
style(Style style) Table
Sets the default style for all cells.
styleFunc(TableStyleFunc func) Table
Sets the style function for per-cell conditional styling.
toString() String
A string representation of this object.
inherited
update(Msg msg) → (ViewComponent, Cmd?)
Updates the component state in response to a message.
inherited
view() String
Renders the current model state for display.
inherited
width(int value) Table
Sets the total table width.
widths(List<int> values) Table
Sets manual column widths.
wrap(bool value) Table
Sets whether text should wrap in cells.
writelnTo(Console io) → void

Available on DisplayComponent, provided by the DisplayComponentExtension extension

Renders the component and writes it to the console.

Operators

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

Constants

headerRow → const int
Row index constant for the header row in styleFunc.