10

How do I save and open file in flutter desktop on Windows. getApplicationDocumentsDirectory is not working on flutter desktop for windows application

Future<String> get _localPath async {
  final directory = await getApplicationDocumentsDirectory();
  print('$directory');
  return directory.path;
}

Throw error.

Exception has occurred
MissingPluginException (MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider))
Alok Kumar
  • 397
  • 1
  • 4
  • 15
  • You tried this https://flutter.dev/docs/cookbook/persistence/reading-writing-files ? – Alexandre Jean May 06 '20 at 06:48
  • @AlexJean That's not working on Windows application as it work on Android, you may try yourself. – Alok Kumar May 06 '20 at 11:06
  • is that link of any help to you? https://stackoverflow.com/questions/57741142/flutter-desktop-flutter-desktop-embedding-how-to-save-file-to-a-hard-drive I see guys downvoted you. To me is a bit unfair especially they did not comment why they did it. – Alexandre Jean May 06 '20 at 11:16

3 Answers3

4

In pubspec.yaml file add (path_provider: ^1.6.24) import package in our file (import 'package:path_provider/path_provider.dart';)

Nikhil Kadam
  • 109
  • 4
1

To get the desktop plugins to work i found i needed to copy the plugins provided by flutter specifically for desktop into my project. I also updated the yaml configuration.

Source for plugins. https://github.com/google/flutter-desktop-embedding/tree/master/plugins/flutter_plugins/path_provider_fde

Note: i believe these plugins will change and eventually become part of the default package installed.

Things like getApplicationDocumentsDirectory are provided by Flutter, but the windows implementation is currently in development, so you have to provide the additional plugins which have the windows/mac/linux implementation. Which can be found on the flutter desktop pages. (link above)

Below is what my folder looks like.

enter image description here

And my pubspec.yaml dependencies: logger: ^0.9.1 dependencies: auto_size_text: ^2.1.0 draggable_scrollbar: ^0.0.4 provider: ^4.0.1 flutter: sdk: flutter file_chooser: git: url: git://github.com/google/flutter-desktop-embedding.git path: plugins/file_chooser ref: 4ee135c path_provider: ^1.5.1 path_provider_macos: ^0.0.1 path_provider_fde: path: ./plugins/flutter_plugins/path_provider_fde window_size: path: ./plugins/window_size url_launcher: ^5.4.0 url_launcher_fde: path: ./plugins/flutter_plugins/url_launcher_fde

Emile
  • 11,451
  • 5
  • 50
  • 63
0
String _localPath = (await _findLocalPath()) + Platform.pathSeparator + 'Download';
final savedDir = Directory(_localPath);
bool hasExisted = await savedDir.exists();
if (!hasExisted) {
  savedDir.create();
}

Pubspec.yami

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^0.1.3
  path_provider: ^1.6.8 

Try to this code dear.

Hitesh sapra
  • 248
  • 2
  • 12