File tree Expand file tree Collapse file tree 2 files changed +33
-10
lines changed
packages/lw_sysapi/lib/src/api Expand file tree Collapse file tree 2 files changed +33
-10
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import 'package:flutter/foundation.dart';
77import 'package:flutter/material.dart' ;
88
99bool supportsShare () => kIsWeb || ! Platform .isLinux;
10+ bool supportsSave () => kIsWeb || ! Platform .isIOS;
1011
1112Future <void > exportFile ({
1213 required BuildContext context,
@@ -18,7 +19,7 @@ Future<void> exportFile({
1819 required String label,
1920 bool share = false ,
2021}) async {
21- if (share && supportsShare ()) {
22+ if (share && supportsShare () || ( ! share && ! supportsSave ()) ) {
2223 return exportUsingShare (
2324 bytes: bytes,
2425 fileName: fileName,
@@ -27,12 +28,14 @@ Future<void> exportFile({
2728 label: label,
2829 );
2930 }
30- return save.exportFile (
31- bytes,
32- fileName,
33- fileExtension,
34- mimeType,
35- uniformTypeIdentifier,
36- label,
37- );
31+ if (supportsSave ()) {
32+ return save.exportFile (
33+ bytes,
34+ fileName,
35+ fileExtension,
36+ mimeType,
37+ uniformTypeIdentifier,
38+ label,
39+ );
40+ }
3841}
Original file line number Diff line number Diff line change 1+ import 'dart:io' ;
12import 'dart:typed_data' ;
23
34import 'package:file_picker/file_picker.dart' ;
5+ import 'package:lw_sysapi/src/api/api.dart' ;
46
57Future <void > exportFile (
68 Uint8List bytes,
@@ -10,11 +12,29 @@ Future<void> exportFile(
1012 String uniformTypeIdentifier,
1113 String label,
1214) async {
13- await FilePicker .platform.saveFile (
15+ if (Platform .isAndroid) {
16+ await platform.invokeMethod ('saveFile' , {
17+ 'mime' : mimeType,
18+ 'data' : bytes,
19+ 'name' : '$fileName .$fileExtension ' ,
20+ });
21+ return ;
22+ }
23+ var file = await FilePicker .platform.saveFile (
1424 dialogTitle: label,
1525 fileName: '$fileName .$fileExtension ' ,
1626 bytes: bytes,
1727 type: FileType .custom,
1828 allowedExtensions: [fileExtension],
1929 );
30+ if (file == null ) return ;
31+ if (! file.endsWith ('.$fileExtension ' )) {
32+ final dotIndex = file.lastIndexOf ('.' );
33+ if (dotIndex != - 1 ) {
34+ file = file.substring (0 , dotIndex);
35+ }
36+ file = '$file .$fileExtension ' ;
37+ }
38+ final outputFile = File (file);
39+ await outputFile.writeAsBytes (bytes);
2040}
You can’t perform that action at this time.
0 commit comments