30 lines
764 B
Dart
30 lines
764 B
Dart
import 'dart:convert';
|
|
import 'dart:js_interop';
|
|
import 'dart:typed_data';
|
|
import 'package:web/web.dart' as web;
|
|
|
|
/// Implémentation web du téléchargement de fichier
|
|
void downloadFile(String content, String fileName) {
|
|
final bytes = Uint8List.fromList(utf8.encode(content));
|
|
|
|
// Créer un Blob avec les données
|
|
final blob = web.Blob(
|
|
[bytes.toJS].toJS,
|
|
web.BlobPropertyBag(type: 'text/csv;charset=utf-8'),
|
|
);
|
|
|
|
// Créer une URL pour le blob
|
|
final url = web.URL.createObjectURL(blob);
|
|
|
|
// Créer un lien de téléchargement et le cliquer
|
|
final anchor = web.document.createElement('a') as web.HTMLAnchorElement;
|
|
anchor.href = url;
|
|
anchor.download = fileName;
|
|
anchor.click();
|
|
|
|
// Nettoyer l'URL
|
|
web.URL.revokeObjectURL(url);
|
|
}
|
|
|
|
|