format method
Converts this node into a BlockElement.
The inline content is laid out as a single left-to-right paragraph by Flutter, which takes care of line breaking, alignment, kerning and ligatures across differently styled spans.
All late variables must be initialized prior to calling this method.
Implementation
@override
BlockElement format(double availableWidth) {
final blockWidth = availableWidth;
final contentWidth = max(blockWidth - style.padding.horizontal, 0.0);
final textAlign = style.textAlign ?? TextAlign.left;
final paragraph = ParagraphTextElement.layout(
child.toInlineSpan(),
maxWidth: contentWidth,
textAlign: textAlign,
);
final dx =
style.padding.left +
(contentWidth - paragraph.width) * _relativeOffset(textAlign);
paragraph.translate(dx, style.padding.top);
final blockHeight = paragraph.height + style.padding.vertical;
final background = makeBackground(
style.background,
blockWidth,
blockHeight,
);
final elements = background == null ? [paragraph] : [background, paragraph];
return GroupElement(
width: blockWidth,
height: blockHeight,
children: elements,
);
}