build method
Implementation
@override
Widget build(BuildContext context, String text, TextStyle? style,
void Function(String url, String title)? onLinkTab) {
final List<Map<int, String>> value = text
.split('\n')
.map<Map<int, String>>(
(e) => e
.split('|')
.where((element) => element.isNotEmpty)
.toList()
.asMap(),
)
.toList();
int maxCol = 0;
for (final each in value) {
if (maxCol < each.keys.length) {
maxCol = each.keys.length;
}
}
if (maxCol == 0) {
return Text("", style: style);
}
return Table(
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
border: TableBorder.all(
width: 1,
color: Theme.of(context).colorScheme.onSurface,
),
children: value
.map<TableRow>(
(e) => TableRow(
children: List.generate(
maxCol,
(index) => Center(
child: MdWidget(
(e[index] ?? "").trim(),
onLinkTab: onLinkTab,
style: style,
),
),
),
),
)
.toList(),
);
}