exportImage method
Generates Uint8List of the ui.Image generated by the renderImage()
method.
Can be converted to image file by writing as bytes.
Implementation
Future<Uint8List?> exportImage() async {
late ui.Image _convertedImage;
if (widget.isSignature) {
final _boundary = _repaintKey.currentContext!.findRenderObject()
as RenderRepaintBoundary;
_convertedImage = await _boundary.toImage(pixelRatio: 3);
} else if (widget.byteArray != null && _controller.paintHistory.isEmpty) {
return widget.byteArray;
} else {
_convertedImage = await _renderImage();
}
final byteData =
await _convertedImage.toByteData(format: ui.ImageByteFormat.png);
return byteData?.buffer.asUint8List();
}