renderThumbnail method

Future<ImageElement?> renderThumbnail({
  1. String? renderedHTML,
  2. bool includeDocumentStyles = true,
  3. String? styles,
  4. int? width = 800,
  5. int? height = 600,
})

Implementation

Future<ImageElement?> renderThumbnail(
    {String? renderedHTML,
    bool includeDocumentStyles = true,
    String? styles,
    int? width = 800,
    int? height = 600}) async {
  renderedHTML ??= renderDomGenerator.generatedHTMLTrees.join('\n');
  if (isEmptyObject(renderedHTML)) return null;

  var svgStyles = '';
  if (includeDocumentStyles) {
    var rules = getAllCssStyleSheet()
        .map((e) => e.rules)
        .whereType<List<CssRule>>()
        .expand((e) => e)
        .toList();

    svgStyles = rules.map((e) => e.cssText).join('\n');
  }

  if (isNotEmptyObject(styles)) {
    svgStyles = '\n$styles';
  }

  var svg = htmlAsSvgContent(renderedHTML,
      width: width, height: height, style: svgStyles);

  var thumbnail = UISVG(parent,
      svgContent: svg, width: '${width}px', height: '${height}px');

  var renderedImage = await thumbnail.buildRenderedImage();

  return renderedImage;
}