render method

  1. @override
Widget render(
  1. NudgeText node,
  2. BuildContext context
)
override

Implementation

@override
Widget render(NudgeText node, BuildContext context) {
  final scope = VariableScopeProvider.of(context);
  // The base style; rich runs inherit it and override only what they set.
  final base = EngageFonts.style(
    TextStyle(
      fontFamily: node.fontFamily,
      fontSize: node.fontSize,
      fontWeight: node.weight,
      color: node.color,
      height: node.lineHeight,
      letterSpacing: node.letterSpacing,
    ),
  );

  if (node.spans.isEmpty) {
    return Text(
      scope.resolve(node.text),
      textAlign: node.align,
      style: base,
      maxLines: node.overflow == 'ellipsis' && node.maxLines > 0
          ? node.maxLines
          : null,
      overflow: node.overflow == 'ellipsis'
          ? TextOverflow.ellipsis
          : node.overflow == 'clip'
              ? TextOverflow.clip
              : TextOverflow.visible,
    );
  }

  // Rich overlay: each run is a TextSpan whose null style fields cascade from
  // the root span's base style; set fields override (mirrors the dashboard).
  return Text.rich(
    TextSpan(
      style: base,
      children: [
        for (final span in node.spans)
          TextSpan(
            text: scope.resolve(span.text),
            style: EngageFonts.style(
              TextStyle(
                fontFamily: span.style.fontFamily ?? node.fontFamily,
                fontWeight: span.style.weight,
                fontSize: span.style.fontSize,
                letterSpacing: span.style.letterSpacing,
                height: span.style.lineHeight,
                color: span.style.color,
                backgroundColor: span.style.highlightColor,
                fontStyle: span.style.italic ? FontStyle.italic : null,
                decoration: span.style.decoration,
                decorationColor: span.style.decorationColor,
                decorationThickness: span.style.decorationThickness,
              ),
              inheritedWeight: node.weight,
              inheritedFontSize: node.fontSize,
            ),
          ),
      ],
    ),
    textAlign: node.align,
    maxLines: node.overflow == 'ellipsis' && node.maxLines > 0
        ? node.maxLines
        : null,
    overflow: node.overflow == 'ellipsis'
        ? TextOverflow.ellipsis
        : node.overflow == 'clip'
            ? TextOverflow.clip
            : TextOverflow.visible,
  );
}