mat*_*eoh 9 dart flutter flutter-windows
在我的 Windows Flutter 项目中,我想运行一些.exe要嵌入到项目中的文件,而不是手动将它们复制/粘贴到正确的位置。
所以我尝试将.exe文件添加到我的assets文件夹中,如下所示:
assets
\exe
\images
Run Code Online (Sandbox Code Playgroud)
并将exe文件夹添加到我的pubspec.yaml文件中,如下所示:
assets
\exe
\images
Run Code Online (Sandbox Code Playgroud)
好消息是:当我构建项目时,exe 文件被复制到正确的位置。坏消息是:我不知道如何exe在 Dart 中获取文件夹的绝对路径。
那么,有没有办法获取exeWindows 项目文件夹的绝对路径,或者是否有另一种方法来嵌入我的.exe文件,以便我可以获取它们的路径并运行它们(使用Process.start())?
谢谢。
以下是我获取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")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1838 次 |
| 最近记录: |