Skip to content

Configuring VS Code Launch Environments

To streamline the development process, you can configure Visual Studio Code to easily run your Flutter application in different environments (demo, development, or production) directly from the “Run and Debug” panel. This avoids the need to manually type the flutter run command with the correct --dart-define arguments each time.

  1. In your project’s root directory, create a folder named .vscode if it doesn’t already exist.
  2. Inside the .vscode folder, create a new file named launch.json.
  3. Copy and paste the following JSON configuration into your launch.json file.
.vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Demo - Flutter News App",
"request": "launch",
"type": "dart",
"program": "lib/main.dart",
"args": [
"--dart-define=APP_ENVIRONMENT=demo"
]
},
{
"name": "Development - Flutter News App",
"request": "launch",
"type": "dart",
"program": "lib/main.dart",
"args": [
"--dart-define=APP_ENVIRONMENT=development",
"--dart-define=BASE_URL=http://localhost:8080"
]
},
{
"name": "Production - Flutter News App",
"request": "launch",
"type": "dart",
"program": "lib/main.dart",
"args": [
"--dart-define=APP_ENVIRONMENT=production",
"--dart-define=BASE_URL=https://api.your-production-domain.com"
]
}
]
}

After saving the file, open the “Run and Debug” panel in VS Code (you can use the shortcut Ctrl+Shift+D). You will now see a dropdown menu at the top with the launch configurations: “Demo - Flutter News App”, “Development - Flutter News App”, and “Production - Flutter News App”.

Simply select the environment you want to run and press the green play button (or F5) to launch the application with the correct settings.