【发布时间】:2021-12-16 05:01:12
【问题描述】:
在 Flutter/dart 中编程时,我需要将参数传递给 VS Code 中的调试会话。我将以下数据添加到launch.json 中,如documentation 中所述。
{
"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 列表也是空的。所以请告诉我我做错了什么?
【问题讨论】:
-
@pskink
but variables are empty, and args list is also empty. -
顺便说一句,您发布的链接是关于“toolArgs”,而不是“args”:
"configurations": [ { "name": "Flutter", "request": "launch", "type": "dart", "toolArgs": [ "--dart-define", "MY_VAR=MY_VALUE", "--dart-define", "MY_OTHER_VAR=MY_OTHER_VALUE" ] } ] -
使用
final debugMode = const String.fromEnvironment('DEBUG_MODE'); -
很遗憾,这没有帮助。
标签: flutter dart visual-studio-code