renderImageAsBytes method

Future<bytes> renderImageAsBytes({
  1. double pixelRatio = 6,
  2. ImageByteFormat format = ui.ImageByteFormat.png,
})

Render a image from widget by this GlobalKey and return as bytes Remember to surround your widget with WidgetsToImage and give it this GlobalKey

Implementation

Future<bytes> renderImageAsBytes({
  double pixelRatio = 6,
  ui.ImageByteFormat format = ui.ImageByteFormat.png,
}) async {
  try {
    final image = await renderImage(pixelRatio: pixelRatio);
    final byteData = await image?.toByteData(format: format);
    if (byteData != null) {
      return byteData.buffer.asUint8List();
    }
    throw Exception("Failed to get image data");
  } catch (e) {
    rethrow;
  }
}