Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

saveFile() not working #832

Closed
BoHellgren opened this issue Sep 20, 2021 · 3 comments
Closed

saveFile() not working #832

BoHellgren opened this issue Sep 20, 2021 · 3 comments
Assignees
Labels
android Issue applies to Android platform web Issue applies to Web platform

Comments

@BoHellgren
Copy link

I tried the new saveFile API in 4.1.0:

Future<void> saveSettings(ArtWork artWork) async {
  String fileName = artWork.title + '.diy';
  String outputFile = await FilePicker.platform.saveFile(
    dialogTitle: 'Please select an output file:',
    fileName: fileName,
  );
  print('output file name $outputFile');
}

But I get this error message, both running on Android and on Web:

errors.dart:202 Uncaught (in promise) Error: UnimplementedError: saveFile() has not been implemented.
    at Object.throw_ [as throw] (errors.dart:251)
    at saveFile (file_picker.dart:156)
    at saveFile.next (<anonymous>)
    at runBody (async_patch.dart:84)
    at Object._async [as async] (async_patch.dart:123)
    at file_picker_web.FilePickerWeb.__.saveFile (file_picker.dart:150)
    at saveSettings (VM28 widgetsweb.dart.lib.js:438)
    at saveSettings.next (<anonymous>)
    at runBody (async_patch.dart:84)
    at Object._async [as async] (async_patch.dart:123)
    at Object.saveSettings (VM28 widgetsweb.dart.lib.js:436)
    at VM28 widgetsweb.dart.lib.js:410
    at Generator.next (<anonymous>)
    at async_patch.dart:45
    at _RootZone.runUnary (zone.dart:1687)
    at _FutureListener.thenAwait.handleValue (future_impl.dart:160)
    at handleValueCallback (future_impl.dart:767)
    at Function._propagateToListeners (future_impl.dart:796)
    at _Future.new.[_completeWithValue] (future_impl.dart:602)
    at async._AsyncCallbackEntry.new.callback (future_impl.dart:640)
    at Object._microtaskLoop (schedule_microtask.dart:40)
    at _startMicrotaskLoop (schedule_microtask.dart:49)
    at async_patch.dart:166

I also tested pickFiles and it works as expected:

Future<void> restoreSettings(ArtWork artWork) async {
  FilePickerResult pickerResult = await FilePicker.platform.pickFiles();
  if (pickerResult.files.first != null){
    String fileName = pickerResult.files.first.name;
    print('picker fileName $fileName');
    Uint8List fileBytes = pickerResult.files.first.bytes;
    print('picker fileBytes $fileBytes');
  }
}

Why do I get the "not implemented" message on saveFile?

D:\>flutter --version
Flutter 2.5.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision ffb2ecea52 (3 days ago) • 2021-09-17 15:26:33 -0400
Engine • revision b3af521a05
Tools • Dart 2.14.2
@BoHellgren BoHellgren added the new issue An issue that hasn't yet been seen from the maintainer label Sep 20, 2021
@miguelpruivo
Copy link
Owner

CC: @philenius

@miguelpruivo miguelpruivo added bug Something isn't working desktop The issue applies to Windows, Linux or MacOS implementations. and removed new issue An issue that hasn't yet been seen from the maintainer labels Sep 20, 2021
@philenius
Copy link
Collaborator

hey @BoHellgren, I'm sorry to disappoint you, but this functionality is only supported on desktop platforms (Linux, macOS, and Windows). In issue #799, @miguelpruivo and I thought that there is no need to implement this functionality on Android / iOS / web.

The docs of saveFile() contain one tiny sentence mentioning these circumstances 😉 :

  /// Opens a save file dialog which lets the user select a file path and a file
  /// name to save a file.
 ... blablabla
  /// This method is only available on desktop platforms (Linux, macOS &
  /// Windows).
... blablabla
  /// Returns [null] if aborted. Returns a [Future<String?>] which resolves to
  /// the absolute path of the selected file, if the user selected a file.
  Future<String?> saveFile({
    String? dialogTitle,
    String? fileName,
    FileType type = FileType.any,
    List<String>? allowedExtensions,
  })
...

@philenius philenius added android Issue applies to Android platform web Issue applies to Web platform and removed bug Something isn't working desktop The issue applies to Windows, Linux or MacOS implementations. labels Sep 20, 2021
@miguelpruivo
Copy link
Owner

@philenius sorry, my bad, didn't noticed that the OP was referring to Android.

Yes, @BoHellgren, like @philenius pointed out, this isn't supported on mobile devices as of now. I'm not sure if it will be even supported at all. I'm sorry for any inconvenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Issue applies to Android platform web Issue applies to Web platform
Projects
None yet
Development

No branches or pull requests

3 participants