16 lines
423 B
Dart
16 lines
423 B
Dart
import 'dart:convert';
|
|
// ignore: avoid_web_libraries_in_flutter
|
|
import 'dart:html' as html;
|
|
|
|
void downloadJsonFileWeb(String jsonData, String fileName) {
|
|
final bytes = utf8.encode(jsonData);
|
|
final blob = html.Blob([bytes]);
|
|
final url = html.Url.createObjectUrlFromBlob(blob);
|
|
|
|
final anchor = html.AnchorElement(href: url)
|
|
..setAttribute('download', fileName)
|
|
..click();
|
|
|
|
html.Url.revokeObjectUrl(url);
|
|
}
|