我需要在flutter/dart编程时,在VS Code中向调试会话传递参数。根据文档的说明,我已将以下数据添加到launch.json
中。
{
"configurations": {
..
// Any custom environment variables to set when running the app with this
// launch config.
"env": {
"DEBUG_MODE": true
}
// Arguments to be passed to the Dart or Flutter app.
"args": [
"--dart-define",
"DEBUG_VALUE=true",
],
}
尝试读取该值:
void main(List<String> args) {
final debugMode = String.fromEnvironment('DEBUG_MODE');
final debugValue = String.fromEnvironment('DEBUG_VALUE');
...
}
但是变量为空,而且args
列表也为空。请给我建议,我做错了什么?
"configurations": [ { "name": "Flutter", "request": "launch", "type": "dart", "toolArgs": [ "--dart-define", "MY_VAR=MY_VALUE", "--dart-define", "MY_OTHER_VAR=MY_OTHER_VALUE" ] } ]
- pskinkfinal debugMode = const String.fromEnvironment('DEBUG_MODE');
。 - pskink