If I define the run configuration as follow, as reported in the documentation here when I try to get variable value from code it is always empty.
"configurations": [
{
"name": "appname (DEV)",
"request": "launch",
"type": "dart",
"program": "lib/main_dev.dart",
"console": "debugConsole",
"flutterMode": "debug",
"args": [
"--flavor",
"dev"
],
"cwd": "${workspaceFolder}",
"toolArgs": [
"--dart-define",
"FIREBASE_ANDROID_API_KEY=xxxxxxxxx",
"--dart-define",
"FIREBASE_IOS_API_KEY=xxxxxxxxxx",
"--dart-define",
"EAS_API_KEY=xxxxxxxxxx",
"--dart-define",
"EAS_TOKEN=xxxxxxxxx",
"--dart-define",
"SIGNING_CERTIFICATE_HASH=xxxxxxxxxx",
"--dart-define",
"DB_PASSWORD=xxxxxxxxxxx"
]
},
]
if from code I do this:
String.fromEnvironment('DB_PASSWORD')
it returns
""
but I expect that the value is the value in the configuration
Add const :
const String.fromEnvironment('DB_PASSWORD')
When running from Flutter, these strings only appear to work when constant (see here). There's a request for a warning about this here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With