build method

  1. @override
Widget build(
  1. BuildContext context,
  2. String text,
  3. TextStyle? style,
  4. TextDirection textDirection,
  5. void onLinkTab(
    1. String url,
    2. String title
    )?,
)
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(),
  );
}