A quick and (relatively) easy tutorial on how to use a customised dart formatter in your dart/flutter project!
Currently works only in VSCode
- VSCode editor
- A dart/flutter project
- This extension, or if it's no longer available, any kind of Run-On-Save extension will do, you'll just have to customize the .vscode/settings.json file for it.
- Clone the https://github.com/dart-lang/dart_style to your pc
- Make edits to whatever you need. (A good idea is to search commits, since then you will just need to revert the changes)
- Compile it using
dart compile exe bin/format.dart
- it will produce anformat.exe
file in thebin
folder. - Move the
format.exe
file to your project directory in the.vscode
folder, and rename it todartfmt.exe
- Copy the settings from .vscode/settings.json to your files, and edit it to your preferences. (Remember: the number after
-l
in the 7th line is the max line length) - Check whether the Dart SDK compiler is disabled in VSCode settings!
- You're ready to go!
- I needed it to stop forcing a blank line after functions, so I went and found this commit, and forced the needsDouble variables to false.
- Yes, I know the current method is a bit janky, but simply writing to the same file creates endless problems, and I couldn't find any better method. If you find one, feel free to share it!
- Add a check if the format was successful before moving the temp file