Flutter Auto Formatting on VSCode

huangapple go评论54阅读模式
英文:

Flutter Auto Formatting on VSCode

问题

最近我对Flutter(在VSCode上)每当我在文件中添加分号时自动格式化我的文件感到非常烦恼...

有没有人知道如何阻止这种情况发生?自动格式化看起来很糟糕,使我的代码非常难以阅读。

我尝试点击VS Code右下角的“Dart”,然后转到编辑Flutter的设置,将formatOnSave设置为false,但这并没有起作用。

英文:

Recently I got super annoyed with flutter (on VSCode) auto-formatting my file whenever I add a semicolon in the file for some reason...

Does anyone know how to stop this from happening? The auto formatting looks horrible and makes my code very hard to read

I tried to click on "Dart" at the bottom right of VS Code then go to edit Flutter based settings, and turned formatOnSave to false, but that did not work

答案1

得分: 1

你可以通过设置"Dart: Enable Sdk Formatter"来完全禁用Dart格式化程序。这将彻底注销格式化程序,因此它不会出现在上下文菜单中,也不会在“formatOnSave”、“formatOnPaste”或“formatOnType”时运行。

或者,如果你希望能够手动调用格式化程序(使用上下文菜单或快捷键),但永远不希望它自动运行,你可以通过将以下内容添加到你的VS Code用户设置来禁用自动运行:

"[dart]": {
    "editor.formatOnSave": false,
    "editor.formatOnPaste": false,
    "editor.formatOnType": false,
}

如果你在首次运行时接受了推荐设置,可能已经定义了这些设置,这种情况下,只需将它们从true更改为false即可。

英文:

You can completely disable the Dart formatter with "Dart: Enable Sdk Formatter" setting. This will unregister the formatter entirely, so it doesn't show up in the context menu, or fire for formatOnSave, formatOnPaste or formatOnType.

Alternatively, if you want to be able to invoke the formatter manually (using the context menu or shortcut keys) but never have it run automatically, you can disable the automatic running by adding this to your VS Code user settings:

"[dart]": {
	"editor.formatOnSave": false,
	"editor.formatOnPaste": false,
	"editor.formatOnType": false,
}

It's possible you already have these defined if you accepted the Recommended Settings on first run, in which case just change them from true to false.

huangapple
  • 本文由 发表于 2023年2月27日 04:21:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75574797.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定