dartfluttercommandprogram-entry-pointargs

How do you pass arguments from command line to main in Flutter/Dart?


How would you run a command and pass some custom arguments with Flutter/Dart so they can then be accessed in the main() call such as:

flutter run -device [my custom arg]

So then I can access it with:

void main(List<String> args) {
  print(args.toString());
}

Thank you.


Solution

  • The arguments for the main method can be declared with the parameter --dart-entrypoint-args (short: -a), e.g.

    flutter run -d linux --dart-entrypoint-args some_file.xml