build method
Widget
build(
- BuildContext context,
- String text,
- TextStyle? style,
- TextDirection textDirection,
- void onLinkTab()?,
override
Implementation
@override
Widget build(
BuildContext context,
String text,
TextStyle? style,
TextDirection textDirection,
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,
textDirection: textDirection,
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(),
textDirection: textDirection,
onLinkTab: onLinkTab,
style: style,
),
),
),
),
)
.toList(),
);
}