22 lines
780 B
Dart
22 lines
780 B
Dart
import 'dart:io';
|
|
import 'dart:typed_data';
|
|
import 'dart:html' as html;
|
|
|
|
// Function to save PDF file on web platforms
|
|
Future<File> savePdfFile(String fileName, Uint8List bytes) async {
|
|
// Use html.AnchorElement to trigger a download
|
|
final blob = html.Blob([bytes], 'application/pdf');
|
|
final url = html.Url.createObjectUrlFromBlob(blob);
|
|
final anchor = html.AnchorElement(href: url)
|
|
..setAttribute('download', fileName)
|
|
..setAttribute('style', 'display: none');
|
|
html.document.body?.children.add(anchor);
|
|
|
|
// Trigger download and clean up
|
|
anchor.click();
|
|
html.document.body?.children.remove(anchor);
|
|
html.Url.revokeObjectUrl(url);
|
|
|
|
// Return a dummy file for web since we can't access the file system directly
|
|
return File('dummy_path_for_web');
|
|
} |