如何在 VS Code 中的 Flutter 中自动添加“const”?

问题描述 投票:0回答:3

在 VS Code 中,如何在按下 (Ctrl + S) 时自动添加 const ?

flutter visual-studio-code constants
3个回答
24
投票

**要在 VS Code 中的 Flutter 中保存文件时添加自动 const 功能,您应该按照以下步骤操作:**

1-) 按 (ctrl + P) 然后搜索 (settings.json) 文件。

2-) 将此代码行添加到那里;

"editor.codeActionsOnSave": {
    "source.fixAll": true
}

6
投票
  • ctrl+ shift+ P
  • 搜索
    settings.json
    • 打开用户设置(Json)

    • 添加以下代码

       "editor.codeActionsOnSave": {
        "source.fixAll": true
      }
      
      

注意:简化并更新了@Emirhan 的答案并进行了必要的更改


4
投票

如果有诸如常量或更改之类可以改进的事情,我建议您申请相同的 flutter 建议,在终端中运行它,仅此而已。

https://docs.flutter.dev/tools/flutter-fix

dart fix --apply
© www.soinside.com 2019 - 2024. All rights reserved.