captureWidget static method
Capture raw RGBA32 data image
Implementation
static Future<CapturedWidget> captureWidget(GlobalKey widgetKey) async {
final RenderRepaintBoundary boundary =
widgetKey.currentContext!.findRenderObject()! as RenderRepaintBoundary;
final ui.Image image = await boundary.toImage(pixelRatio: 1.0);
final ByteData? byteData =
await image.toByteData(format: ui.ImageByteFormat.rawRgba);
if (byteData == null) {
return CapturedWidget(ByteData(0), Size.zero);
}
return CapturedWidget(
byteData,
Size(image.width.toDouble(), image.height.toDouble()),
);
}