Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to surround flutter widget in vscode

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

like image 936
arkade Avatar asked Sep 18 '18 06:09

arkade


People also ask

How do you wrap a container in VS Code?

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.

Is VS Code good for Flutter?

VS Code is a lightweight editor that has great Flutter support, good extensibility and sees widespread use across the developer community.


6 Answers

Sure!

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

enter image description here

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

like image 92
Rémi Rousselet Avatar answered Oct 06 '22 08:10

Rémi Rousselet


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.

like image 44
nonybrighto Avatar answered Oct 06 '22 08:10

nonybrighto


⚠️ 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.

like image 34
fiona Avatar answered Oct 06 '22 07:10

fiona


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

Ctrl+Shift+R

like image 37
Pawan Jain Avatar answered Oct 06 '22 08:10

Pawan Jain


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

like image 37
Sabeer Avatar answered Oct 06 '22 07:10

Sabeer


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

like image 32
Agidigbi Ayodeji Victor Avatar answered Oct 06 '22 07:10

Agidigbi Ayodeji Victor