renderSvgToPicture function

PictureInfo renderSvgToPicture(
  1. String rawSvg, {
  2. Size? size,
  3. SvgTheme? theme,
  4. ColorMapper? colorMapper,
})

Parses rawSvg and records it into a ui.Picture.

When size is omitted the SVG is recorded at its intrinsic size. Pass a theme to control currentColor and font-relative units, and a colorMapper to substitute colors while parsing.

The returned PictureInfo owns a native ui.Picture; call PictureInfo.dispose when finished with it.

Implementation

PictureInfo renderSvgToPicture(
  String rawSvg, {
  ui.Size? size,
  SvgTheme? theme,
  ColorMapper? colorMapper,
}) {
  final document = SvgParser.parse(rawSvg);
  applySvgTheme(document, theme: theme, colorMapper: colorMapper);

  final renderSize = size ?? svgIntrinsicSize(document);
  final recorder = ui.PictureRecorder();
  final canvas = ui.Canvas(recorder);
  AnimatedSvgPainter(
    document: document,
    hasAnimations: false,
  ).paint(canvas, renderSize);

  return PictureInfo(picture: recorder.endRecording(), size: renderSize);
}