currentDartFilePath function
Returns the path to the caller's .dart
file.
If packageRelative
is true, returns a path relative to the package root.
If packageRelative
is false, returns an absolute path.
This does not work for Dart for the Web.
Note that Platform.script does not work for import
ed files and
consequently does not work with the Dart test runner.
Implementation
String currentDartFilePath({bool packageRelative = false}) {
var caller = stacktrace.Frame.caller(1);
return packageRelative ? caller.library : caller.uri.toFilePath();
}