getUint8List method

Future<Uint8List?> getUint8List(
  1. GlobalKey<State<StatefulWidget>> widgetKey
)

Converting Widget to PNG

Implementation

Future<Uint8List?> getUint8List(GlobalKey widgetKey) async {
  RenderRepaintBoundary boundary =
      widgetKey.currentContext!.findRenderObject() as RenderRepaintBoundary;
  var image = await boundary.toImage(pixelRatio: 2.0);
  ByteData? byteData = await (image.toByteData(format: ImageByteFormat.png));
  return byteData?.buffer.asUint8List();
}