my formatter keeps doing such a thing. When I try to place method calls in separate lines. For example I have such a code:
main() {
SomeObject()
.someMethod()
.someMethodWithArgument('someArgument')
.someMethodWithArgument('someOtherArgument');
}
After hitting quick format, I get something like that:
main() {
SomeObject().someMethod().someMethodWithArgument('someArgument')
.someMethodWithArgument('someOtherArgument');
}
It drives me crazy and it is totally unreadable in my opinion. I played around with format settings in Android Studio preferences but I cannot find anything that would fix this particular formatting issue.
What is the best way to ensure consistent formatting in the Flutter code? DartFMT command replaces the whitespaces with the Dart-guidelines formatting.
To automatically format the code in the current source code window, right-click in the code window and select Format Document . You can add a keyboard shortcut to this VS Code Preferences. To automatically format code whenever you save a file, set the editor. formatOnSave setting to true .
Open Setting > Preferences > Keymap and search for the one that says "Reformat code with 'dart format'". There you can customize it as needed.
Use the dart format command to replace the whitespace in your program with formatting that follows Dart guidelines. This is the same formatting that you can get when using an IDE or editor that has Dart support. For more information about this and other dart commands, see the Dart command-line tool page.
There's no way to configure dartfmt
by design. However, you can technically force it to match the formatting you have using comments on each line:
main() {
SomeObject() //
.someMethod() //
.someMethodWithArgument('someArgument') //
.someMethodWithArgument('someOtherArgument');
}
It's obviously not ideal, and won't be consistent with other Dart code in the ecosystem, but if the formatting bothers you that much it's the only option.
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