Flutter: add flavors configuration into Visual Studio
Asked Answered
G

4

13

My flutter application has different flavors. In Android Studio everything is setup in the flavor configuration panel, but where can I do that in Visual Studio Code?

I guess I have to edit the configuration.json but I cant find any reference online on how to do it.

I do not want every time to type flutter run --flavor app1 -t lib/main_app1.dart

Giaimo answered 3/7, 2019 at 13:1 Comment(0)
L
34

You can pass additional arguments using a launch.json. If you don't already have one, click the Cog icon in the Debug sidebar and then select Flutter in the snippet-completion list. You can then add an args section, like this:

{
    "name": "Flutter",
    "request": "launch",
    "type": "flutter",
    "args": [
        "--flavor",
        "app1"
    ]
}
Loving answered 26/7, 2019 at 8:48 Comment(3)
what do you mean with: "--flavor", "red"Giaimo
It was just an example of a flavor name - you could put app1 here based on your example (I edited my code to make it clearer).Loving
@AndreaMiotto it should be marked accepted answer :DIncisure
S
7

You have to edit your launch.json file

{
            "name": "dev", // you can add nickname for it
            "request": "launch",
            "type": "dart",
            "args": [
                "--flavor", //flavor name
                "dev",
                "-t", // if your have different main file
                "lib/main_dev.dart" 
            ]
},
Simonne answered 16/9, 2021 at 10:7 Comment(0)
A
4
{
  "name": "App Dev",
  "cwd": ".",
  "request": "launch",
  "type": "dart",
  "flutterMode": "debug",
  "program": "lib/main_dev.dart",
  "args": ["--flavor", "dev"],
}
Advance answered 27/5, 2022 at 9:37 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Dial
S
0

for me including both program and args worked.

{
        "name": "project (prod)",
        "request": "launch",
        "type": "dart",
        "program": "lib/main_prod.dart",
        "args": [
            "--flavor", //flavor name
            "prod",
            "-t", // if your have different main file
            "lib/main_prod.dart"
        ]
    },
Syst answered 14/2 at 7:27 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Dial

© 2022 - 2024 — McMap. All rights reserved.