Renders style-able flex ascii tables.
- Customizable table borders
- Multiline rows
- Column size control
- Min and max Column widths
- Flex column widths
- Percentage based column widths
- Cell text alignment
- Cell padding
- Merged cells
- Text truncation and ellipsis
import 'package:text_table/text_table.dart';
main() {
final tab = TableRenderer().render([
['Messi', 'Barcelona FC', 80],
['Christiano Ronaldo', 'Real Madrid', 30],
['Luiz Suarez', 'Barcelona FC', 50]
], columns: [
'Player',
'Team',
'Goals'
]);
print(tab);
}
┌──────────────────┬────────────┬─────┐
│ Player │ Team │Goals│
┝━━━━━━━━━━━━━━━━━━┿━━━━━━━━━━━━┿━━━━━┥
│Messi │Barcelona FC│80 │
├──────────────────┼────────────┼─────┤
│Christiano Ronaldo│Real Madrid │30 │
├──────────────────┼────────────┼─────┤
│Luiz Suarez │Barcelona FC│50 │
└──────────────────┴────────────┴─────┘
final tab = TableRenderer().render([
['Messi', 'Barcelona FC', 80],
['Christiano Ronaldo', 'Real Madrid', 30],
['Luiz Suarez', 'Barcelona FC', 50]
], columns: [
ColSpec(name: 'Player', width: Fixed(25), align: Align.left),
ColSpec(name: 'Team', width: Fixed(25), align: Align.center),
ColSpec(name: 'Goals', width: Fixed(10), align: Align.right)
]);
print(tab);
┌─────────────────────────┬─────────────────────────┬──────────┐
│ Player │ Team │ Goals │
┝━━━━━━━━━━━━━━━━━━━━━━━━━┿━━━━━━━━━━━━━━━━━━━━━━━━━┿━━━━━━━━━━┥
│Messi │ Barcelona FC │ 80│
├─────────────────────────┼─────────────────────────┼──────────┤
│Christiano Ronaldo │ Real Madrid │ 30│
├─────────────────────────┼─────────────────────────┼──────────┤
│Luiz Suarez │ Barcelona FC │ 50│
└─────────────────────────┴─────────────────────────┴──────────┘
import 'package:text_table/text_table.dart';
main() {
final tab = TableRenderer(padding: Padding.same(1)).render([
['Messi', 'Barcelona FC', 80],
['Christiano Ronaldo', 'Real Madrid', 30],
['Luiz Suarez', 'Barcelona FC', 50]
], columns: [
'Player',
'Team',
ColSpec(name: 'Goals', padding: Padding.same(2)),
]);
print(tab);
}
┌────────────────────┬──────────────┬─────────┐
│ Player │ Team │ Goals │
┝━━━━━━━━━━━━━━━━━━━━┿━━━━━━━━━━━━━━┿━━━━━━━━━┥
│ Messi │ Barcelona FC │ 80 │
├────────────────────┼──────────────┼─────────┤
│ Christiano Ronaldo │ Real Madrid │ 30 │
├────────────────────┼──────────────┼─────────┤
│ Luiz Suarez │ Barcelona FC │ 50 │
└────────────────────┴──────────────┴─────────┘
import 'package:text_table/text_table.dart';
main() {
final tab = TableRenderer(padding: Padding.same(2)).render([
['Messi', 'Barcelona FC', 80],
['Christiano Ronaldo', 'Real Madrid', 30],
['Luiz Suarez', 'Barcelona FC', 50]
], columns: [
ColSpec(name: 'Player', width: Flex(2)),
ColSpec(name: 'Team', width: Flex(1), minWidth: Fixed(15)),
ColSpec(name: 'Goals', width: Flex(1), align: Align.right)
], width: 50);
print(tab);
}
┌─────────────────┬───────────────────┬──────────┐
│ Player │ Team │ Goals │
┝━━━━━━━━━━━━━━━━━┿━━━━━━━━━━━━━━━━━━━┿━━━━━━━━━━┥
│ Messi │ Barcelona FC │ 80 │
├─────────────────┼───────────────────┼──────────┤
│ Christiano Ro │ Real Madrid │ 30 │
│ naldo │ │ │
├─────────────────┼───────────────────┼──────────┤
│ Luiz Suarez │ Barcelona FC │ 50 │
└─────────────────┴───────────────────┴──────────┘
Use border
field of TableRenderer
to customize the border style of the table.
final tab = TableRenderer(border: Border.doubleLines)
.render(rows, columns: columns);
print(tab);
╔══════════════════╤════════════╤═════╗
║ Player │ Team │Goals║
╠══════════════════╪════════════╪═════╣
║Messi │Barcelona FC│80 ║
╟──────────────────┼────────────┼─────╢
║Christiano Ronaldo│Real Madrid │30 ║
╟──────────────────┼────────────┼─────╢
║Luiz Suarez │Barcelona FC│50 ║
╚══════════════════╧════════════╧═════╝
final tab =
TableRenderer(border: Border.compact).render(rows, columns: columns);
print(tab);
Player Team Goals
-------------------------------------
Messi Barcelona FC 80
Christiano Ronaldo Real Madrid 30
Luiz Suarez Barcelona FC 50
final tab =
TableRenderer(border: Border.round).render(rows, columns: columns);
print(tab);
╭──────────────────┬────────────┬─────╮
│ Player │ Team │Goals│
┝━━━━━━━━━━━━━━━━━━┿━━━━━━━━━━━━┿━━━━━┥
│Messi │Barcelona FC│80 │
├──────────────────┼────────────┼─────┤
│Christiano Ronaldo│Real Madrid │30 │
├──────────────────┼────────────┼─────┤
│Luiz Suarez │Barcelona FC│50 │
╰──────────────────┴────────────┴─────╯