captureWidgetPng function
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();
}
}