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 children = context.builtChildrenMap!;

  assert(
    children.keys.isNotEmpty,
    "The OnImageTapExtension has been thwarted! It no longer has an `img` child",
  );

  final actualImage = children.keys.first;

  return WidgetSpan(
    child: Builder(builder: (buildContext) {
      return GestureDetector(
        child: CssBoxWidget.withInlineSpanChildren(
          children: children.values.toList(),
          style: context.styledElement!.style,
        ),
        onTap: () {
          if (MultipleTapGestureDetector.of(buildContext) != null) {
            MultipleTapGestureDetector.of(buildContext)!.onTap?.call();
          }
          onImageTap(
            actualImage.attributes['src'],
            actualImage.attributes,
            actualImage.element,
          );
        },
      );
    }),
  );
}