Just wondering if there is a shortcut or extension in visual studio code to surround a code block - or more specifically highlight the widget name and then surround that widgets children.
Often is the case where I have created, lets say a:
Padding(
padding: EdgeInsets.all(10.0),
child: Container(
...
But then after some writing, i want to surround that Padding
with something else, like a Column
or Row
.
As is, I need to prefix the Padding
with Row( child:
and then scroll down and add the new ),` bracket
Is there not a way to just select the Padding
and then tell vs code that I am going to prefix this so add the bracket for me?
Pretty sure I have seen this in action in IntelliJ
How to use. Select one or more block of widgets. Press Alt + C to wrap inside Container or press Alt + S to wrap inside Stack . Change class name to whatever you want.
VS Code is a lightweight editor that has great Flutter support, good extensibility and sees widespread use across the developer community.
Sure!
Vscode offer a few refactor options, including Wrap with Column
:
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.
⚠️ If wrap with Column
is not shown on Right-click - refactor:
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.
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.
Right click on the widget and choose 'refactor', then 'wrap with new widget'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With