visitElementAfter method
Called when an Element has been reached, after its children have been visited.
Will not be called if visitElementBefore returns false
.
Implementation
@override
void visitElementAfter(MarkdownElement element) {
final current = _tree.removeLast();
final type = current.type;
final parent = _tree.last;
final builder = _builders[type]!;
final textSpan = builder.createText(current, parent.style);
if (textSpan != null) {
current.children.add(createRichText(textSpan));
}
current.children.replaceRange(
0,
current.children.length,
compressWidgets(current.children),
);
final widget = builder.buildWidget(current, parent);
final isBlock = builder.isBlock(current);
if (widget != null) {
// Add spacing between block elements
_tree.last.children.addIfTrue(
SizedBox(
height: _blockSpacing,
// TODO(Zhiguang): Remove it when this issue is fixed:
// https://github.com/flutter/flutter/issues/104548
child: selectable
? const Text(' \n', selectionColor: Colors.transparent)
: null,
),
isBlock && _tree.last.children.isNotEmpty,
);
if (widget is InlineWraper) {
parent.children.addAll(widget.children);
} else {
if (!isBlock) {
_checkInlineWidget(widget);
}
parent.children.add(widget);
}
}
if (_keepLineEndingsWhen == type) {
_keepLineEndingsWhen = null;
}
_gestureRecognizers.remove(type);
}