flutterdartvisual-studio-codeideeditor

How to make Dart files break one line per parameter in VsCode?


I am learning Flutter/Dart, and in the video series I am following, there is only one parameter per line, as follows:

body: Container(
        width: double.infinity,
        height: double.infinity,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center, 
          children: [
            Text('Counter ${counter}'),
            CustomSwitch(),
          ]),
      )

but in my editor, the line won't break per parameter.

Since I am using Dart Recommended Settings, I thought it would be the same here in my editor, but what happens is the following:

body: Container(
        width: double.infinity,
        height: double.infinity,
        child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
          Text('Counter ${counter}'),
          CustomSwitch(),
        ]),

See how the 'child' property has both mainAxisAliment and children in the same line?

How do I setup my settings, so that doesn't happen, and one parameter is shown per line?

I thought I could just reduce the line width (currently 80, as suggested), but that wouldn't break exactly one parameter per line.


Solution

  • Adding coma,whenever possible will provide your desire result. In your case, you can add another coma after ],. This will format the code.

     CustomSwitch(),
        ],
      ),