captureScreenshot function

Future<String> captureScreenshot(
  1. GlobalKey<State<StatefulWidget>> widgetKey
)

Implementation

Future<String> captureScreenshot(GlobalKey widgetKey) async {
  await Future.delayed(const Duration(seconds: 1));
  final boundary =
      widgetKey.currentContext?.findRenderObject() as RenderRepaintBoundary?;
  final image = await boundary?.toImage(
    pixelRatio: Catalog().pixelRatio,
  );
  final byteData = await image?.toByteData(format: ui.ImageByteFormat.png);
  if (byteData == null) {
    return '';
  }
  return base64.encode(byteData.buffer.asUint8List().toList());
}