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) {
  late final Widget widget;

  if (context.elementName == "svg") {
    widget = _renderSvgTag(context);
  } else if (context.styledElement is ImageElement) {
    if (_matchesSvgAssetUri(context)) {
      widget = _renderAssetSvg(context);
    } else if (_matchesSvgDataUri(context)) {
      widget = _renderDataSvg(context);
    } else if (_matchesSvgNetworkSource(context)) {
      widget = _renderNetworkSvg(context);
    }
  }

  return WidgetSpan(
    child: CssBoxWidget(
      style: context.styledElement!.style,
      childIsReplaced: true,
      child: widget,
    ),
  );
}