build method

  1. @override
Widget build(
  1. BuildContext context,
  2. String text,
  3. GptMarkdownConfig config
)
override

Implementation

@override
Widget build(
  BuildContext context,
  String text,
  final GptMarkdownConfig config,
) {
  var match = exp.firstMatch(text.trim());
  var conf = config.copyWith(
      style: [
    Theme.of(context)
        .textTheme
        .headlineLarge
        ?.copyWith(color: config.style?.color),
    Theme.of(context)
        .textTheme
        .headlineMedium
        ?.copyWith(color: config.style?.color),
    Theme.of(context)
        .textTheme
        .headlineSmall
        ?.copyWith(color: config.style?.color),
    Theme.of(context)
        .textTheme
        .titleLarge
        ?.copyWith(color: config.style?.color),
    Theme.of(context)
        .textTheme
        .titleMedium
        ?.copyWith(color: config.style?.color),
    Theme.of(context)
        .textTheme
        .titleSmall
        ?.copyWith(color: config.style?.color),
  ][match![1]!.length - 1]);
  return config.getRich(
    TextSpan(
      children: [
        ...(MarkdownComponent.generate(
          context,
          "${match[2]}",
          conf,
        )),
        if (match[1]!.length == 1) ...[
          const TextSpan(
            text: "\n ",
            style: TextStyle(fontSize: 0, height: 0),
          ),
          WidgetSpan(
            child: CustomDivider(
              height: 2,
              color: config.style?.color ??
                  Theme.of(context).colorScheme.outline,
            ),
          ),
        ],
      ],
    ),
  );
}