parseTree method

InlineSpan parseTree(
  1. RenderContext context,
  2. StyledElement tree
)

parseTree converts a tree of StyledElements to an InlineSpan tree.

parseTree is responsible for handling the customRenders parameter and deciding what different Style.display options look like as Widgets.

Implementation

InlineSpan parseTree(RenderContext context, StyledElement tree) {
  // Merge this element's style into the context so that children
  // inherit the correct style
  RenderContext newContext = RenderContext(
    buildContext: context.buildContext,
    parser: this,
    tree: tree,
    style: context.style.copyOnlyInherited(tree.style),
    key: AnchorKey.of(key, tree),
  );

  for (final entry in customRenders.keys) {
    if (entry.call(newContext)) {
      buildChildren() => tree.children.map((tree) => parseTree(newContext, tree)).toList();
      if (newContext.parser.selectable && customRenders[entry] is SelectableCustomRender) {
        selectableBuildChildren() => tree.children.map((tree) => parseTree(newContext, tree) as TextSpan).toList();
        return (customRenders[entry] as SelectableCustomRender).textSpan.call(newContext, selectableBuildChildren);
      }
      if (newContext.parser.selectable) {
        return customRenders[entry]!.inlineSpan!.call(newContext, buildChildren) as TextSpan;
      }
      if (customRenders[entry]?.inlineSpan != null) {
        return customRenders[entry]!.inlineSpan!.call(newContext, buildChildren);
      }
      return WidgetSpan(
        child: ContainerSpan(
          newContext: newContext,
          style: tree.style,
          shrinkWrap: newContext.parser.shrinkWrap,
          child: customRenders[entry]!.widget!.call(newContext, buildChildren),
        ),
      );
    }
  }
  return const WidgetSpan(child: SizedBox(height: 0, width: 0));
}