0

I'm working with Flutter and Dart.

In my project, under /lib directory, I have some dart files and a dart file for every "screen" (or "page", or "activity").

I would need to obtain programmatically the name of the dart file.

If I do the file name request in screen_edituser.dart I would need to obtain "screen_edituser" in a variable.

I tried to use Platform.script but I obtain always "main.dart" whatever the dart file name of the project is.

Greenlight
  • 115
  • 10
  • 1
    https://stackoverflow.com/a/67695494/ – jamesdlin Apr 19 '22 at 16:54
  • Not the required result: stacktrace.Frame.caller(1).library gives "package:flutter/src/widgets/framework.dart" – Greenlight Apr 19 '22 at 17:14
  • 1
    How are you using it? `stacktrace.Frame.caller(1).library` gives the path to the *caller*, so if you're using that directly, it won't be what you want. In that case, you'll want `stacktrace.Frame.caller(0).library` instead. The code cited at the linked answer assumes that you would be accessing it via `currentDartFilePath()`. – jamesdlin Apr 19 '22 at 17:46
  • Does this answer your question? [How do I get the directory of the current script, in Dart?](https://stackoverflow.com/questions/19623313/how-do-i-get-the-directory-of-the-current-script-in-dart) – SteAp Apr 19 '22 at 23:49
  • stacktrace.Frame.caller(0).library works! Thank you very much. I understood now how caller(1) and caller(0) work. – Greenlight Apr 20 '22 at 10:17

0 Answers0