【问题标题】:getApplicationDocumentsDirectory is not working on flutter desktop (windows)getApplicationDocumentsDirectory 在颤振桌面(Windows)上不起作用
【发布时间】:2020-08-20 22:06:55
【问题描述】:

如何在 Windows 的 Flutter 桌面中保存和打开文件。 getApplicationDocumentsDirectory 不适用于 Windows 应用程序的颤振桌面

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

抛出错误。

Exception has occurred
MissingPluginException (MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider))

【问题讨论】:

标签: android windows flutter dart desktop


【解决方案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 

亲爱的,试试这个代码。

【讨论】:

  • _findLocalPath() 未定义。哪个包有这个功能
【解决方案2】:

为了让桌面插件正常工作,我发现我需要将 Flutter 专门为桌面提供的插件复制到我的项目中。我还更新了 yaml 配置。

插件的来源。 https://github.com/google/flutter-desktop-embedding/tree/master/plugins/flutter_plugins/path_provider_fde

注意:我相信这些插件会改变并最终成为默认安装包的一部分。

getApplicationDocumentsDirectory 之类的东西是 Flutter 提供的,但是 windows 实现目前正在开发中,所以你必须提供具有 windows/mac/linux 实现的附加插件。可以在颤振桌面页面上找到。 (以上链接)

下面是我的文件夹的样子。

还有我的 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

【讨论】:

    【解决方案3】:

    在 pubspec.yaml 文件中添加 (path_provider: ^1.6.24) 在我们的文件中导入包(import 'package:path_provider/path_provider.dart';)

    【讨论】:

      猜你喜欢
      • 2022-06-14
      • 1970-01-01
      • 2022-08-11
      • 1970-01-01
      • 2018-11-17
      • 2021-02-20
      • 2021-04-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多