withStatusColumn static method
Creates a table with status column styling.
Automatically colors values in the specified column based on content.
Implementation
static Table withStatusColumn(
List<String> headers,
List<List<Object?>> rows, {
int statusColumn = -1, // -1 means last column
Map<String, Color>? statusColors,
}) {
final colors =
statusColors ??
{
'active': Colors.success,
'done': Colors.success,
'ok': Colors.success,
'success': Colors.success,
'inactive': Colors.warning,
'pending': Colors.warning,
'waiting': Colors.warning,
'error': Colors.error,
'failed': Colors.error,
'failure': Colors.error,
};
return Table()
..headers(headers)
..rows(rows)
..border(style_border.Border.rounded)
..styleFunc((row, col, data) {
final targetCol = statusColumn < 0
? headers.length + statusColumn
: statusColumn;
if (row == Table.headerRow) {
return Style().bold();
}
if (col == targetCol) {
final lowerData = data.toLowerCase();
for (final entry in colors.entries) {
if (lowerData.contains(entry.key)) {
return Style().foreground(entry.value);
}
}
}
return null;
});
}