获取启动脚本的目录路径

Get path to directory from which script has been started

比如我有这样的结构:

/home/user <- my current dir
/home/user/app/bin/main.dart <- entry point of my application

如何获取启动脚本的文件夹的路径?例如,我通过以下方式从 /home/user 文件夹启动 main.dart

dart app/bin/main.dart

main.dart 内部,我需要获取路径 /home/user。这可能吗?

我想这就是您要找的。

import 'dart:io';

void main() {
  print(Platform.script);
  print(Platform.script.toFilePath(windows: true));

  // or

  print(Directory.current.absolute.path);
}

另见 How do I get the script path in Dart?