takeWidgetShot method
Future<File>
takeWidgetShot(
- GlobalKey<
State< previewKey,StatefulWidget> > - String imagePath, {
- double pixelRatio = 1.0,
Implementation
Future<File> takeWidgetShot(GlobalKey previewKey, String imagePath,
{double pixelRatio = 1.0}) async {
RenderRepaintBoundary boundary =
previewKey.currentContext!.findRenderObject()! as RenderRepaintBoundary;
ui.Image image = await boundary.toImage(pixelRatio: pixelRatio);
ByteData? byteData = await image.toByteData(format: ui.ImageByteFormat.png);
Uint8List pngBytes = byteData!.buffer.asUint8List();
await File(imagePath).create();
await File('$imagePath').writeAsBytes(pngBytes);
File imgFile = new File('$imagePath');
return imgFile;
}