onMarkup method

  1. @override
HypertextSpan onMarkup(
  1. List<HypertextSpan>? children,
  2. MarkupContext ctx
)
override

Implementation

@override
HypertextSpan onMarkup(List<HypertextSpan>? children, MarkupContext ctx) {
  final gaps = ctx.getDoubles(tag);
  EdgeInsets? padding = switch (gaps?.length) {
    1 => EdgeInsets.all(gaps![0]),
    2 => EdgeInsets.symmetric(vertical: gaps![0], horizontal: gaps[1]),
    3 => EdgeInsets.only(
        top: gaps![0],
        left: gaps[1],
        right: gaps[1],
        bottom: gaps[2],
      ),
    4 => EdgeInsets.only(
        left: gaps![0],
        top: gaps[1],
        right: gaps[2],
        bottom: gaps[3],
      ),
    _ => null,
  };

  final hor = ctx.getDoubles('hor');
  final ver = ctx.getDoubles('ver');
  if (padding == null && (hor.isNotEmpty || ver.isNotEmpty)) {
    var hors = switch (hor?.length) {
      1 => (hor![0], hor[0]),
      2 => (hor![0], hor[1]),
      _ => (0.0, 0.0),
    };
    var vers = switch (ver?.length) {
      1 => (ver![0], ver[0]),
      2 => (ver![0], ver[1]),
      _ => (0.0, 0.0),
    };

    padding = EdgeInsets.only(
      left: hors.$1,
      right: hors.$2,
      top: vers.$1,
      bottom: vers.$2,
    );
  }

  if (padding == null) return HypertextTextSpan(children: children);

  final alignment = ctx.switchT(ctx.get('alignment'), mpPLAlignment);
  final baseline = ctx.switchT(ctx.get('baseline'), mpBaselines);

  final effectiveAlignment =
      alignment ?? this.alignment ?? PlaceholderAlignment.baseline;
  final effectiveBaseline = baseline ??
      this.baseline ??
      (this.alignment == null ? TextBaseline.alphabetic : null);
  return HypertextWidgetSpan(
    alignment: effectiveAlignment,
    baseline: effectiveBaseline,
    child: Padding(
      padding: padding,
      child: Text.rich(HypertextTextSpan(children: children)),
    ),
  );
}