Skip to content

Commit 03e262d

Browse files
Merge pull request #2 from abineshPalanisamy/master
KB file added
2 parents 75a0c77 + 68bfc05 commit 03e262d

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

lib/helper/save_file_mobile_desktop.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,17 @@ Future<void> saveAndLaunchFile(List<int> bytes, String fileName) async {
1414
Platform.isIOS ||
1515
Platform.isLinux ||
1616
Platform.isWindows) {
17-
final Directory directory =
18-
await path_provider.getApplicationSupportDirectory();
19-
path = directory.path;
17+
if (Platform.isAndroid) {
18+
final Directory? directory =
19+
await path_provider.getExternalStorageDirectory();
20+
if (directory != null) {
21+
path = directory.path;
22+
}
23+
} else {
24+
final Directory directory =
25+
await path_provider.getApplicationSupportDirectory();
26+
path = directory.path;
27+
}
2028
} else {
2129
path = await path_provider_interface.PathProviderPlatform.instance
2230
.getApplicationSupportPath();

lib/helper/save_file_web.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import 'dart:async';
2+
import 'dart:convert';
3+
import 'dart:html';
4+
5+
///To save the excel sheet in the web platform.
6+
Future<void> saveAndLaunchFile(List<int> bytes, String fileName) async {
7+
AnchorElement(
8+
href:
9+
'data:application/octet-stream;charset=utf-16le;base64,${base64.encode(bytes)}')
10+
..setAttribute('download', fileName)
11+
..click();
12+
}

0 commit comments

Comments
 (0)