12

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

3 Answers 3

5

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

-1
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.

1 Comment

_findLocalPath() is undefined. which package has this function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.