Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dart-define return empty string vscode Flutter

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

like image 276
Camillo bucciarelli Avatar asked Sep 07 '26 06:09

Camillo bucciarelli


1 Answers

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.

like image 166
Danny Tuppeny Avatar answered Sep 10 '26 03:09

Danny Tuppeny