如何在 vscode 环绕颤振小部件

只是想知道在可视化工作室代码中是否有一个快捷方式或扩展来围绕代码块——或者更具体地突出显示小部件名称,然后围绕该小部件的子部件。

通常情况下,我已经创造了,让我们说:

Padding(
padding: EdgeInsets.all(10.0),
child: Container(
...

但是在一些写作之后,我想用一些其他的东西来包围这个 Padding,比如 Column或者 Row。 就是这样,我需要在 Padding前面加上 Row( child:,然后向下滚动,添加新的) ,’括号

有没有一种方法只是选择 Padding,然后告诉 vs 代码,我要前缀这样添加我的括号?

我很确定我在 IntelliJ 上看到过这种情况

52739 次浏览

Sure!

Vscode offer a few refactor options, including Wrap with Column:

enter image description here

Just right-click on a widget and press "Refactor".

Place your cursor in the widget you want to edit and use CTRL + . shortcut to see the options. Use CMD + . for MacOS. That will do it.

Right click on the widget and choose 'refactor', then 'wrap with new widget'

On VS Code on Windows just right-click on any widget and press "Refactor" or use the keyboard shortcut

Ctrl+Shift+R

If any one looking for Android Studio its option + return in Mac and Alt + Enter in Windows.

⚠️ If wrap with Column is not shown on Right-click - refactor:

  • on Window : Ctrl + .
  • on MacOs : + .

Then Right-click > wrap with Column


Here is the reason why this happen: https://dartcode.org/docs/refactorings-and-code-fixes/ . Also documented there: you can now bind shortcuts to the refactor actions:

Ctrl+. in Code opens the “lightbulb” menu showing all code fixes/refactors. Code v1.20 gained the ability to keybind quickfixes. To do this you should edit your keybindings.json file and include the ID of the refactor as found below.

In Ubuntu VSCode it is also ctrl + . where as in Ubuntu Android Studio or Intellij it was alt + enter.

Simply press: Ctrl + dot on windows or Command + dot on mac

and a list pops up showing wrapping options!

  1. Click on the widget
  2. Press CTRL + SHIFT + R