How to prevent dartfmt to leave the space between getter and setter

304 Views Asked by At

This is what I want.

int _foo = 42;
int get foo => _foo;

But when I format the code using dartfmt, it changes to

int _foo = 42;

int get foo => _foo;

How can I prevent this behavior?

1

There are 1 best solutions below

0
iDecode On BEST ANSWER

There are two types of formatting. One is regular formatting provided by the IDE, also known as Reformat Code and the other is provided by Flutter CLI, also known as Reformat Code with Dartfmt.

By default, when you press the keyboard shortcut option + command + L, it runs the former Reformat Code (which doesn't use dartfmt to format the code).

To fix this behavior, override keyboard shortcut in your IDE. Go to

File > Settings > Keymap > Editor Actions > Reformat Code with Dartfmt 

and assign it the above mentioned shortcut.