saveBytesToFile method

Future saveBytesToFile(
  1. Uint8List bytes,
  2. String fileName
)

Implementation

Future<dynamic> saveBytesToFile(Uint8List bytes, String fileName) async {
  if (kIsWeb) {
    // 🔹 WEB: Create a virtual file and trigger download
    final blob = html.Blob([widget.file.bytes!]);
    return html.Url.createObjectUrlFromBlob(blob);
  } else {
    // 🔹 MOBILE/DESKTOP: Save the file locally
    final tempDir = await getTemporaryDirectory();
    final file = File("${tempDir.path}/$fileName");
    await file.writeAsBytes(bytes);
    return file;
  }
}