Why does this if:
if (value == null || value.trim().isEmpty || !value.contains('@'))
breaks into multiple lines upon save?:
if (value == null ||
value.trim().isEmpty ||
!value.contains('@')) {
return 'Please enter a valid email address';
}
I would like to keep it on a single line, is that possible with Dart and Flutter? I am using Visual Studio Code
That behavior comes from dart format, which applies certain formatting rules to your code.
To disable auto-formatting upon saving files, Open User Settings (JSON) and add this setting (check first if this setting is already existing in the file):
{
// ...
"[dart]": {
"editor.formatOnSave": false,
// ...
}
}
Alternatively, you might want to increase the allowed characters for a single line. You can change the value for dart.lineLength
to change the formatting behavior and as well set the vertical ruler line to visually draw the limit line on your editor.
{
// ...
"dart.lineLength": 80,
"editor.rulers": [80],
}