captureWidgetPng function

Future<PngResult> captureWidgetPng(
  1. Widget widget, {
  2. required Size size,
  3. double pixelRatio = 3,
})

Renders widget offscreen at size and rasterizes it — the camera lane, so its only possible warning is the widget throwing on the way to the picture.

Implementation

Future<PngResult> captureWidgetPng(
  Widget widget, {
  required Size size,
  double pixelRatio = 3,
}) async {
  var mounted = OffscreenWidget.mount(widget, size: size);
  try {
    var image = await mounted.boundary.toImage(pixelRatio: pixelRatio);
    var png = await image.toByteData(format: ui.ImageByteFormat.png);
    return PngResult(png!.buffer.asUint8List(), _buildWarnings(mounted));
  } finally {
    mounted.dispose();
  }
}