saveScreenshot function

Future<String> saveScreenshot(
  1. List<int> bytes,
  2. String fileName
)

Implementation

Future<String> saveScreenshot(List<int> bytes, String fileName) async {
  final blob = html.Blob([bytes]);
  final url = html.Url.createObjectUrlFromBlob(blob);

  try {
    final anchor = html.AnchorElement(href: url)
      ..download = fileName
      ..style.display = 'none';

    html.document.body?.append(anchor);
    anchor.click();
    anchor.remove();
    return fileName;
  } finally {
    html.Url.revokeObjectUrl(url);
  }
}