captureWidgetSvg function

Future<SvgResult> captureWidgetSvg(
  1. Widget widget, {
  2. required Size size,
  3. List<RenderFont> fonts = const [],
  4. CaptureOptions? options,
})

Renders widget offscreen at size and captures it as SVG — the widget-first door for widgets that are not part of any running tree.

Implementation

Future<SvgResult> captureWidgetSvg(
  Widget widget, {
  required Size size,
  List<RenderFont> fonts = const [],
  CaptureOptions? options,
}) async {
  var mounted = OffscreenWidget.mount(widget, size: size);
  try {
    var result = await captureSvg(
      mounted.boundary,
      size: size,
      fonts: fonts,
      options: options,
    );
    return SvgResult(result.text, [
      ..._buildWarnings(mounted),
      ...result.warnings,
    ]);
  } finally {
    mounted.dispose();
  }
}