getApplicationDocumentsDirectory is not working on flutter desktop (windows)

11,161

Solution 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

Solution 2

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.

Share:
11,161
Alok Kumar
Author by

Alok Kumar

Updated on June 04, 2022

Comments

  • Alok Kumar
    Alok Kumar almost 2 years

    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))