build method
void
build(
- ParagraphBuilder builder, {
- TextScaler textScaler = TextScaler.noScaling,
- List<
PlaceholderDimensions> ? dimensions,
override
Apply the properties of this object to the given ParagraphBuilder, from which a Paragraph can be obtained.
The textScaler parameter specifies a TextScaler that the text and
placeholders will be scaled by. The scaling is performed before layout,
so the text will be laid out with the scaled glyphs and placeholders.
The dimensions parameter specifies the sizes of the placeholders.
Each PlaceholderSpan must be paired with a PlaceholderDimensions
in the same order as defined in the InlineSpan tree.
Implementation
@override
void build(
ui.ParagraphBuilder builder, {
TextScaler textScaler = TextScaler.noScaling,
List<PlaceholderDimensions>? dimensions,
}) {
assert(debugAssertIsValid());
final bool hasStyle = style != null;
if (hasStyle) {
builder.pushStyle(style!.getTextStyle(textScaler: textScaler));
}
if (text != null) {
try {
builder.addText(text!);
} on ArgumentError catch (exception, stack) {
FlutterError.reportError(FlutterErrorDetails(
exception: exception,
stack: stack,
library: 'painting library',
context: ErrorDescription('while building a MTextSpan'),
silent: true,
));
// Use a Unicode replacement character as a substitute for invalid text.
builder.addText('\uFFFD');
}
}
final List<InlineSpan>? children = this.children;
if (children != null) {
for (final InlineSpan child in children) {
child.build(
builder,
textScaler: textScaler,
dimensions: dimensions,
);
}
}
if (hasStyle) {
builder.pop();
}
}