Table class

A widget for displaying tabular columns of data with optional row selection.

Column Widths and Layout Alignment

  • Layout alignments are governed by columnWidths, representing the physical column span sizes in character cells.
  • Cell text content is truncated or space-padded to exactly fit the specified width of its column.
  • Separate cells within the same row are separated by a space divider character.

Row Selection and Scrolling

  • Selected row index is tracked via selectedRowIndex.
  • The selected row is highlighted using selectedRowStyle (by default, reverse video).
  • Dynamic scroll tracking keeps the selected row inside the visible viewport: adjustScroll calculates the required scrollOffset such that scrollOffset <= selectedRowIndex < scrollOffset + viewportHeight.

Example Usage

Table(
  headers: const ['Name', 'Role'],
  columnWidths: const [10, 15],
  rows: const [
    ['Alice', 'Developer'],
    ['Bob', 'Designer'],
  ],
  selectedRowIndex: 0,
);

Properties and Settings

Property Type Description
headers List<String> Header titles of the columns.
rows List<List> Grid rows containing values or sub-widgets.
columnWidths List<int> Custom column widths in character count.
selectedRowIndex int The index of the row currently selected/active.
selectedRowStyle Style Highlighter styling for the selected row cells.
Inheritance

Constructors

Table({required List<String> headers, required List<List> rows, required List<int> columnWidths, int selectedRowIndex = 0, Style headerStyle = const Style(modifiers: Modifier.bold), Style rowStyle = Style.empty, Style selectedRowStyle = const Style(modifiers: Modifier.reverse), Style borderStyle = const Style(modifiers: Modifier.dim)})
Creates a new Table widget with the provided data and column definitions.

Properties

borderStyle → Style
Styling for structural borders and dividers.
final
columnWidths → List<int>
The defined widths for each column, in character cells.
final
hashCode → int
The hash code for this object.
no setterinherited
headers → List<String>
The text labels for each column header.
final
headerStyle → Style
Styling applied to the table header labels.
final
key → Key?
The optional key for this widget.
finalinherited
rows → List<List>
The rows of data, containing text or widget elements.
final
rowStyle → Style
Styling applied to standard unselected rows.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
scrollOffset ↔ int
The current vertical scrolling offset index.
getter/setter pair
selectedRowIndex ↔ int
The index of the currently highlighted row.
getter/setter pair
selectedRowStyle → Style
Styling applied to the highlighted row.
final

Methods

adjustScroll(int viewportHeight) → void
Adjusts the scroll offset based on the selected row and table height.
createElement() → Element
Creates an Element to manage this widget's location in the tree.
override
getIntrinsicHeight(int width) → int
Computes the intrinsic height of this widget under the given width constraint.
inherited
getIntrinsicWidth(int height) → int
Computes the intrinsic width of this widget under the given height constraint.
inherited
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.
inherited