incrediblezayed / file_saver

A simple flutter plugin for saving files in all platforms
https://pub.dev/packages/file_saver
BSD 3-Clause "New" or "Revised" License
75 stars 103 forks source link

not Work saveAs in windows #119

Open rezadevelopers2 opened 5 months ago

rezadevelopers2 commented 5 months ago

`

   await FileSaver.instance.saveAs(
      name: DateTime.now().toString().replaceAll(" ",  "_"),
      ext: ".json",
      mimeType: MimeType.json,
      bytes: Uint8List.fromList(utf8.encode(jsonEncode(jsonStrings))),

    )

`

This code works correctly for Android But for the Windows and web version, the file is not saved and does not give any error

YarosMallorca commented 4 months ago

I'm facing this issue, anyone found a solution??

dasyad00 commented 4 months ago

It is mentioned in the README that "you can call saveAs() only available for android and iOS & macOS at the moment". There is a simple workaround, but ideally this would be addressed inside the plugin itself.

final filePath = await FileSaver.instance.saveAs(
  name: fileName,
  bytes: Uint8List(),
  ext: ".$extension",
  mimeType: mimeType,
);
if (filePath == null) {
  // cancelled prompt
  return;
}
// TODO FileSaver.instance.saveAs() as of 0.2.13 on Windows
// only prompts the user for the desired file location, but does not write
// the file passed in.
if (Platform.isWindows) {
  final file = File(filePath);
  await file.writeAsBytes(fileModel.data);
}

If the maintainers need some help with implementing this, I have some time to address this issue.