toPngBytes method
convert canvas to dart:ui ui.Image and then to PNG represented in Uint8List
height and width should be at least as big as the drawings size
Will return null if there are no points.
Implementation
Future<Uint8List?> toPngBytes({int? height, int? width}) async {
final ui.Image? image = await toImage(height: height, width: width);
if (image == null) {
return null;
}
final ByteData? bytes = await image.toByteData(format: ui.ImageByteFormat.png);
return bytes?.buffer.asUint8List();
}