onMarkup method
Implementation
@override
HypertextSpan onMarkup(List<HypertextSpan>? children, MarkupContext ctx) {
final url = ctx.get('src');
HypertextSpan? span;
if (url.isNotEmpty) {
double? width = ctx.getDouble('width');
double? height = ctx.getDouble('height');
if (width == null && height == null) {
final s = ctx.getDoubles('size');
if (s?.length == 1) {
width = height = s![0];
} else if (s?.length == 2) {
width = s![0];
height = s[1];
}
}
final fit = ctx.switchT(ctx.get('fit'), mpBoxFit);
final alignment = ctx.switchT(ctx.get('align'), mpAlignment);
final plAlignment = ctx.switchT(ctx.get('alignment'), mpPLAlignment);
final baseline = ctx.switchT(ctx.get('baseline'), mpBaselines);
final effectiveAlignment =
plAlignment ?? this.alignment ?? PlaceholderAlignment.middle;
final effectiveBaseline = baseline ?? this.baseline;
final builder = imageBuilder ?? imageMarkupBuilder;
span = HypertextWidgetSpan(
alignment: effectiveAlignment,
baseline: effectiveBaseline,
child: Builder(
builder: (c) {
return builder(
c,
url!,
width: width,
height: height,
fit: fit,
alignment: alignment,
) ??
const SizedBox.shrink();
},
),
);
}
// 包装图片及其子元素到一个元素中
if (children.isNotEmpty) {
span = HypertextTextSpan(
children: [if (span != null) span, ...?children],
);
}
return span ?? kEmptyHypertextSpan;
}