up and download data
This commit is contained in:
15
lib/helpers/web_download_helper.dart
Normal file
15
lib/helpers/web_download_helper.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
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);
|
||||
}
|
||||
3
lib/helpers/web_download_helper_stub.dart
Normal file
3
lib/helpers/web_download_helper_stub.dart
Normal file
@@ -0,0 +1,3 @@
|
||||
void downloadJsonFileWeb(String jsonData, String fileName) {
|
||||
throw UnsupportedError('Web download is only supported on web platform');
|
||||
}
|
||||
Reference in New Issue
Block a user