24

I am using Android studio to develop a flutter app, when I click reformat code with dart format it breaks in unpleasing format. enter image description here

Even though there is lot of space it breaks the line, how can i increase the line width?

Alvin John Babu
  • 1,710
  • 2
  • 16
  • 26
  • 1
    Check if its a plugin causing the issue or check this out if it might help https://stackoverflow.com/questions/30851617/how-to-set-max-line-length-in-android-studio-code-editor – kenn Nov 16 '19 at 17:08
  • 3
    Thanks for your comment, I changed Settings->Editor -> Code style -> Dart -> Wrapping and braces (tab) -> ``changed Hard wrap`` at to '150' – Alvin John Babu Nov 16 '19 at 18:13

5 Answers5

60

I solved this issue by changing Settings -> Editor -> Code Style -> Dart -> Line length to 150

NM Naufaldo
  • 1,032
  • 1
  • 12
  • 30
Alvin John Babu
  • 1,710
  • 2
  • 16
  • 26
9

FOR MAC OS:

Android Studio -> Preferences -> Editor -> Code Style -> Dart -> Line length: int

Bryan Neuberger
  • 198
  • 2
  • 4
7

Go to settings -> Editor -> Code Style -> Dart, you can change line length to what ever value you want, but based on Effective dart style, it's better to avoid lines longer than 80 characters. see this docs https://dart.dev/guides/language/effective-dart/style

enter image description here

Cevin Ways
  • 984
  • 11
  • 13
2

I'm not sure how to change the settings, maybe with an Android Studio plugin, but as described in the Dart docs you should avoid lines with more than 80 characters of code. Try to structure your code a bit then you have more overview instead of squeezing everything in one method, widget or whatever together

Link to Dart docs

  • 1
    IMHO, this rule has negative effect in common. Actually it is rudimental rule from the past. As Linus Torvalds said: `People with restrictive hardware shouldn't make it more inconvenient for people who have better resources. Yes, we'll accommodate things to within reasonable limits. But no, 80-column terminals in 2020 isn't "reasonable" any more as far as I'm concerned. People commonly used 132-column terminals even back in the '80s, for chrissake, don't try to make 80 columns some immovable standard.` – Sergio Tskhovrebov Feb 13 '22 at 06:16
2

For VS Code:

File -> Preferences -> Settings -> Dart&Flutter: Dart: Line Length

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
  • This does not answer the question which specifically concerns Android Studio. Nevertheless, your answer might be useful for VS Code users. – CEO tech4lifeapps Mar 10 '21 at 05:36