【问题标题】:getLibraryDirectory not working for desktop appgetLibraryDirectory 不适用于桌面应用程序
【发布时间】:2021-03-05 15:49:01
【问题描述】:

我正在开发 Flutter 桌面应用程序,但遇到了问题。我想为数据存储创建本地数据库。我正在使用 path_provider 插件来获取用于保存数据库文件的目录路径。函数 getLibraryDirectory() 在我的应用程序中不起作用。我也在创建数据库时调试我的应用程序,这个函数抛出异常“UnimplementedError: getLibraryPath() has not been implemented”。

这是我正在使用的插件。 https://pub.dev/packages/path_provider

任何人都可以帮助我。谢谢

【问题讨论】:

    标签: database flutter dart flutter-desktop plug


    【解决方案1】:

    我查看了包的源代码,在 Windows 和 Linux 上没有实现方法 getLibraryDirectory(),因为调用此方法所需的属性 getLibraryPath() 也没有实现。基于源 getLibraryDirectory() 似乎仅在 MacOS 上实现。

    以下是应该为 Windows 和 Linux 实施的方法:

    • getTemporaryDirectory()
    • getApplicationSupportDirectory()
    • getApplicationDocumentsDirectory()
    • getDownloadsDirectory()

    还有一个仅限Windows

    • getPath(String folderID) // Retrieve any known folder from Windows.

    【讨论】:

    • 好的,知道了。非常感谢。你能告诉我为什么flutter桌面应用程序的构建exe文件在另一个桌面上运行时没有返回目录路径。我正在使用 getApplicationSupportDirectory() 这个方法来获取保存数据库文件的目录路径,但它没有返回任何路径。当我运行应用程序时,代码在我的桌面上运行良好。可能是什么问题?
    • 老实说,如果没有任何代码示例,我将无法判断,但如果您想要一个完整的答案,这将是另一个问题。
    猜你喜欢
    • 2012-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-19
    • 2012-11-25
    相关资源
    最近更新 更多