valueOf method

ReportValue valueOf(
  1. ReportTemplateText template,
  2. ReportScope scope
)

Value of a single-placeholder template ({{item.price}}) or the interpolated text otherwise. Exporters use this to keep numbers typed.

Implementation

ReportValue valueOf(ReportTemplateText template, ReportScope scope) {
  final List<ReportTextSegment> segs = template.segments
      .where(
        (ReportTextSegment s) =>
            s is! ReportLiteralSegment || s.text.trim().isNotEmpty,
      )
      .toList(growable: false);
  if (segs.length == 1) {
    final ReportTextSegment only = segs.first;
    if (only is ReportExpressionSegment && only.format == null) {
      return evaluate(only.expression, scope);
    }
  }
  return ReportText(interpolateParsed(template, scope));
}