saveBytes static method

Future<void> saveBytes({
  1. required String printName,
  2. required String fileType,
  3. required Uint8List bytes,
  4. String? path,
})

Implementation

static Future<void> saveBytes({
  required String printName,
  required String fileType,
  required Uint8List bytes,
  String? path,
}) async {
  final blob = html.Blob([bytes].jsify() as JSArray<JSAny>);
  final url = html.URL.createObjectURL(blob);
  final anchor = html.document.createElement('a') as html.HTMLAnchorElement
    ..href = url
    ..style.display = 'none'
    ..download = '$printName.$fileType';
  html.document.body!.children.add(anchor);
  anchor.click();
  html.document.body!.children.delete(anchor);
  html.URL.revokeObjectURL(url);
}