toWidget method

  1. @override
Widget toWidget(
  1. RenderContext context
)
override

Implementation

@override
Widget toWidget(RenderContext context) {
  List<InlineSpan>? childrenList = children.map((tree) => context.parser.parseTree(context, tree)).toList();
  List<InlineSpan> toRemove = [];
  for (InlineSpan child in childrenList) {
    if (child is TextSpan && child.text != null && child.text!.trim().isEmpty) {
      toRemove.add(child);
    }
  }
  for (InlineSpan child in toRemove) {
    childrenList.remove(child);
  }
  InlineSpan? firstChild = childrenList.isNotEmpty == true ? childrenList.first : null;
  return ExpansionTile(
      key: AnchorKey.of(context.parser.key, this),
      expandedAlignment: Alignment.centerLeft,
      title: elementList.isNotEmpty == true && elementList.first.localName == "summary" ? StyledText(
        textSpan: TextSpan(
          style: style.generateTextStyle(),
          children: firstChild == null ? [] : [firstChild],
        ),
        style: style,
        renderContext: context,
      ) : Text("Details"),
      children: [
        StyledText(
          textSpan: TextSpan(
            style: style.generateTextStyle(),
            children: getChildren(childrenList, context, elementList.isNotEmpty == true && elementList.first.localName == "summary" ? firstChild : null)
          ),
          style: style,
          renderContext: context,
        ),
      ]
  );
}