Search code examples
flutterdartvisual-studio-codeformatprettier

VS Code : Format document is working weird on Flutter


When i click "Format Document" button inside of page, it looks like this,

enter image description here


Solution

  • From what I can tell, you are trying to solve the awkward line wrapping and deep nesting problem. When your code gets nested as deep as it is, it hits the column word wrap limit and the limit forces forces the formatter to break items that would normally be on one line into several. There are a couple things you can do:

    1. Best option: Refactor your code and split it into multiple classes/ files. That will make it so that you don't have as deeply nested code and it will make it more readable as well as more maintainable.
    2. Go to the vs code settings and search for Dart: Line Length and edit the value to set when the file starts wrapping content.