owlnext-dropzone
Owlnext dropzone wrapper
FileUtils.downloadFile() -> Breaking change on web
if you want to use FileUtils.downloadFile() on web context, you will need to inject a specific behavior from your app. create a file in your app, loaded only in library.html context (web) and call
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:universal_html/html.dart';
import 'package:owlnext_dropzone/owlnext_dropzone.dart';
/// Utility to enable file downloads on Flutter Web when using `owlnext_dropzone`.
///
/// # Why
/// By default, `owlnext_dropzone` cannot handle web downloads without
/// depending on `universal_html`. This class injects a web-only implementation
/// so your app controls the download behavior.
///
/// # How
/// - Call [InitWebDownload.setup] in `main.dart`.
/// - On Web, it registers a custom download function that:
/// 1. Encodes file bytes to Base64
/// 2. Creates a temporary `<a>` element with a `data:` URI
/// 3. Triggers the browser’s native download
/// 4. Cleans up the element
///
/// # Example
/// ```dart
/// void main() {
/// InitWebDownload.setup();
/// runApp(MyApp());
/// }
/// ```
class InitWebDownload {
static void setup() {
if (kIsWeb) {
DownloadFileWebBypass().setDownloadFileWebFunction(_downloadFileWebImplementation);
}
}
Future<void> _downloadFileWebImplementation(Uint8List bytes, String fileName, String extension) async {
final base64 = base64Encode(bytes);
final anchor = AnchorElement(href: 'data:application/octet-stream;base64,$base64')
..target = 'blank'
..download = fileName;
document.body?.append(anchor);
anchor.click();
anchor.remove();
}
}
Debugging
to see debug messages (in debugModeOnly), put this in your app main.dart
OwlnextDropzoneDebuger.kDebugOwlnextDropzone = true;