toPngBytes method

Future<Uint8List?> toPngBytes()

convert canvas to dart:ui Image and then to PNG represented in Uint8List

Implementation

Future<Uint8List?> toPngBytes() async {
  if (!kIsWeb) {
    final ui.Image? image = await toImage();
    if (image == null) {
      return null;
    }
    final ByteData? bytes = await image.toByteData(
      format: ui.ImageByteFormat.png,
    );
    return bytes?.buffer.asUint8List();
  } else {
    return _toPngBytesForWeb();
  }
}