繁体   English   中英

在 VSCode 中调试当前打开的 Flutter 文件

[英]Debug current open Flutter file in VSCode

我正在用 VS Code 编写一个 Flutter 教程项目,其中包含多个main()函数。

例如:

main.dart  //Contains a main() function
step1.dart //Contains a main() function
step2.dart //Contains a main() function

如果我打开了step1.dart ,那么按 F5 会在调试模式下运行main.dart而不是step1.dart

我可以 hover 将鼠标悬停在 step1.dart 中的main() step1.dart上,然后 select 从上下文菜单中“调试”。 这按预期工作并在调试中运行step1.dart 但是,没有关联的快捷方式。

我可以按什么在调试模式下运行活动打开的文件,而不是main.dart

只要我有在一个工作空间上拥有多个flutter项目的经验(反馈不是太好),关键是设置预构建过程配置文件.vscode/launch.json ,您可以获得更多关于调试的信息# _启动配置

创建文件时,它看起来像:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Flutter",
            "request": "launch",
            "type": "dart",
        }
    ]
}

然后添加"program": "lib/your-entry-point.dart"

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "main",
            "request": "launch",
            "type": "dart",
            "program": "lib/main.dart"
        },{
            "name": "step1",
            "request": "launch",
            "type": "dart",
            "program": "lib/step1.dart"
        },{
            "name": "step2",
            "request": "launch",
            "type": "dart",
            "program": "lib/step2.dart"
        }
    ]
}

这将创建以下启动选项。

启动选项

我在.vscode文件夹中制作了这个launch.json文件。 工作起来很有魅力。

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Dart: Current File",
      "type": "dart",
      "request": "launch",
      "program": "${file}",
      "cwd": "${fileDirname}"
    },
  ]
}

以下是您可以在launch.json中使用的变量。

https://code.visualstudio.com/docs/editor/variables-reference

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM