saveAsUint8List method
Implementation
Future<Uint8List?> saveAsUint8List({double pixelRatio = 2}) async {
// Clear all borders before capturing the image.
clearAllBorders();
try {
Uint8List? pngBytes;
await WidgetsBinding.instance.endOfFrame;
// Capture the image of the widget.
RenderRepaintBoundary boundary =
LindiStickerWidget.globalKey.currentContext?.findRenderObject()
as RenderRepaintBoundary;
ui.Image image = await boundary.toImage(pixelRatio: pixelRatio);
ByteData? byteData =
await image.toByteData(format: ui.ImageByteFormat.png);
pngBytes = byteData?.buffer.asUint8List();
return pngBytes;
} catch (e) {
rethrow;
}
}