6

在我用于 Windows 的 Flutter 项目中,我想运行一些.exe我想嵌入到我的项目中的文件,而不是手动将它们复制/粘贴到正确的位置。

所以我尝试.exe在我的assets文件夹中添加文件,如下所示:

assets
  \exe
  \images

exe并在我的文件中添加文件夹,pubspec.yaml如下所示:

flutter:
  assets:
    - assets/images/
    - assets/exe/

好消息是:当我构建项目时,exe 文件被复制到正确的位置。坏消息是:我不知道如何exe在 Dart 中获取我的文件夹的绝对路径。

exe那么,有没有一种方法可以获取Windows 项目的文件夹的绝对路径,或者是否有另一种方法可以嵌入我的.exe文件,以便我可以获取它们的路径并运行它们(使用Process.start())?

谢谢。

4

1 回答 1

0

这是我为获取exe文件夹的绝对路径所做的(仅在 Windows 上测试过):

// returns the abolute path of the executable file of your app:
String mainPath = Platform.resolvedExecutable;

// remove from that path the name of the executable file of your app:
mainPath = mainPath.substring(0, mainPath.lastIndexOf("\\"));

// concat the path with '\data\flutter_assets\assets\exe', where 'exe' is the
// directory where are the executable files you want to run from your app:
Directory directoryExe = Directory("$mainPath\\data\\flutter_assets\\assets\\exe")
于 2021-12-30T09:46:01.900 回答