I try to pass an environment variable from vscode to the swift file in flutter but seems like the swift file cannot pick it.
The launch file I am using for vscode
{
"name": "myapp (debug alpha)",
"request": "launch",
"type": "dart",
"flutterMode": "debug",
"args": [
"--flavor",
"alpha",
"--dart-define",
"environment=alpha"
],
"env": {
"MARKETING_VERSION": "1.0.0",
"GOOGLE_MAP_API_KEY": "xxxxxx"
}
},
The code in AppDelegate.swift is
if let googleMapApiKey = ProcessInfo.processInfo.environment["GOOGLE_MAP_API_KEY"] {
GMSServices.provideAPIKey(googleMapApiKey)
}
When I run my app by running the launch, it exits immediately when the google map is launched. Then I directly run GMSServices.provideAPIKey(xxx) and the google map can be launched. So I guess the GOOGLE_MAP_API_KEY is not picked from the environment.
Can anyone please help on it? Thank you