build method
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) {
final element = context.styledElement as ImageElement;
final imageStyle = Style(
width: element.width,
height: element.height,
).merge(context.styledElement!.style);
late Widget child;
if (_matchesBase64Image(context)) {
child = _base64ImageRender(context, imageStyle);
} else if (_matchesAssetImage(context)) {
child = _assetImageRender(context, imageStyle);
} else if (_matchesNetworkImage(context)) {
child = _networkImageRender(context, imageStyle);
} else {
// Our matcher went a little overboard and matched
// something we can't render
return TextSpan(text: element.alt);
}
return WidgetSpan(
child: CssBoxWidget(
style: imageStyle,
childIsReplaced: true,
child: child,
),
);
}