build method

  1. @override
InlineSpan build(
  1. ExtensionContext context
)

The final step in the chain. Converts the StyledElement tree, with its attached Style elements, into an InlineSpan tree that includes Widget/TextSpans that can be rendered in a RichText widget.

Implementation

@override
InlineSpan build(ExtensionContext context) {
  String texStr = _parseMathRecursive(context.styledElement!.element!, '');
  return WidgetSpan(
    child: CssBoxWidget(
      style: context.styledElement!.style,
      childIsReplaced: true,
      child: Math.tex(
        texStr,
        mathStyle: MathStyle.display,
        textStyle: context.styledElement!.style.generateTextStyle(),
        onErrorFallback: (FlutterMathException e) {
          if (onMathErrorBuilder != null) {
            return onMathErrorBuilder!
                .call(texStr, e.message, e.messageWithType);
          } else {
            return Text(e.message);
          }
        },
      ),
    ),
  );
}