getAlignedHeaderBlock method

  1. @override
Future<List<Widget>> getAlignedHeaderBlock(
  1. String line, [
  2. TextStyle? style
])
override

Implementation

@override
Future<List<pw.Widget>> getAlignedHeaderBlock(String line, [pw.TextStyle? style]) async {
  final RegExpMatch match = Constant.ALIGNED_HEADER_PATTERN.firstMatch(line)!;
  final List<pw.Widget> widgets = <pw.Widget>[];
  final String hLevel = match.group(1)!;
  final String alignment = match.group(2)!;
  String content = match.group(3)!;
  //Verify if there's a error like: into a <h[n]> <span style="line-lineSpacing: 3.0;font-size: 14">Header into a span</span>
  //resolving alignments
  final pw.Alignment al = alignment.resolvePdfBlockAlign;
  final pw.TextAlign textAlign = alignment.resolvePdfTextAlign;
  //verify first if the header contains html new lines
  //remove br's
  final double currentFontSize = hLevel.resolveHeaderLevel();
  final pw.TextStyle header_style = style?.copyWith(fontSize: currentFontSize) ?? defaultTextStyle.copyWith(fontSize: currentFontSize);
  final List<pw.InlineSpan> spans = await _getStylesSpans(content, header_style, false, false);
  widgets.add(
    pw.Container(
      padding: const pw.EdgeInsets.symmetric(vertical: 7),
      alignment: al,
      child: pw.RichText(
        textAlign: textAlign,
        softWrap: true,
        overflow: pw.TextOverflow.span,
        text: pw.TextSpan(children: spans),
      ),
    ),
  );
  return widgets;
}