getApplicationDocumentsDirectory 不适用于 flutter 桌面 (windows)
getApplicationDocumentsDirectory is not working on flutter desktop (windows)
如何在 Windows 的 flutter desktop 中保存和打开文件。 getApplicationDocumentsDirectory 不适用于 windows 应用程序
的 flutter 桌面
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))
为了让桌面插件工作,我发现我需要将 flutter 专门为桌面提供的插件复制到我的项目中。我还更新了 yaml 配置。
注意:我相信这些插件会改变并最终成为默认安装包的一部分。
Flutter 提供了 getApplicationDocumentsDirectory 之类的东西,但是 windows 实现目前正在开发中,因此您必须提供具有 windows/mac/linux 实现的附加插件。可以在 flutter 桌面页面上找到。 (link 以上)
下面是我的文件夹的样子。
还有我的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
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
亲爱的试试这个代码。
在pubspec.yaml文件中添加(path_provider:^1.6.24)
在我们的文件中导入包 (import 'package:path_provider/path_provider.dart';)
如何在 Windows 的 flutter desktop 中保存和打开文件。 getApplicationDocumentsDirectory 不适用于 windows 应用程序
的 flutter 桌面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))
为了让桌面插件工作,我发现我需要将 flutter 专门为桌面提供的插件复制到我的项目中。我还更新了 yaml 配置。
注意:我相信这些插件会改变并最终成为默认安装包的一部分。
Flutter 提供了 getApplicationDocumentsDirectory 之类的东西,但是 windows 实现目前正在开发中,因此您必须提供具有 windows/mac/linux 实现的附加插件。可以在 flutter 桌面页面上找到。 (link 以上)
下面是我的文件夹的样子。
还有我的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
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
亲爱的试试这个代码。
在pubspec.yaml文件中添加(path_provider:^1.6.24) 在我们的文件中导入包 (import 'package:path_provider/path_provider.dart';)