Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code Flutter Format is Not Working with My Indent Space Value

I wasted my all day and i didnt understand what is going on. I'm using Visual Studio Code 1.40.2 and i am learning Flutter 3.60. Sometimes Flutter codes turn unreadable because of indent space. I only wanted to create more space (indent space) but when i use format option, tab size is turning again 2. I looked too many web sites including Stackoverflow and unfortunately i didnt find solution.It turned annoying. This is my config file: (Thanks for help)

{
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
"editor.fontSize": 18,
"editor.fontFamily": "Consolas, 'Courier New', monospace, ",
"dart.openDevTools": "flutter",
"workbench.colorTheme": "Night Owl (No Italics)",
"workbench.iconTheme": "material-icon-theme",
"editor.fastScrollSensitivity": 8,
"editor.tabSize": 8,
"editor.insertSpaces": true,
"editor.wordWrap": "on",
"editor.smoothScrolling": true,
"editor.cursorBlinking": "expand",
"editor.cursorSmoothCaretAnimation": true,
"editor.fontWeight": "400",
"outline.showFields": false,

"[dart]": {
    "editor.tabSize": 6,
    "editor.insertSpaces": true,
    "editor.detectIndentation": false,
},

}

  • I changed editor.insertSpaces false and true and nothing changed.
  • editor.detectIndentation true or false is not working.
  • I added this block but didnt worked.

    "[flutter]": { "editor.tabSize": 6, "editor.insertSpaces": true, "editor.detectIndentation": false, },

This is my simple code:

import 'package:flutter/material.dart';

class GridListe extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GridView.count(
        crossAxisCount: 3,
        primary: false,
        padding: EdgeInsets.all(10),
        crossAxisSpacing: 20,
        mainAxisSpacing: 40,
        children: <Widget>[
            Container(
                alignment: Alignment.center,
                color: Colors.teal,
                child: Text(
                "Salam",
                textAlign: TextAlign.center,
                ),
            ),
        ],
    );
  }
}

When i use format code (Shift + alt + p) Codes indent space or tab size turn 2 and it will make me crazy.

import 'package:flutter/material.dart';

class GridListe extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GridView.count(
      crossAxisCount: 3,
      primary: false,
      padding: EdgeInsets.all(10),
      crossAxisSpacing: 20,
      mainAxisSpacing: 40,
      children: <Widget>[
        Container(
          alignment: Alignment.center,
          color: Colors.teal,
          child: Text(
            "Salam",
            textAlign: TextAlign.center,
          ),
        ),
      ],
    );
  }
}
like image 929
Burak İbrahim Ünal Avatar asked Dec 05 '19 20:12

Burak İbrahim Ünal


People also ask

What is the best way to ensure consistent formatting in Flutter code?

What is the best way to ensure consistent formatting in the Flutter code? DartFMT command replaces the whitespaces with the Dart-guidelines formatting.

How do I turn on auto indent in Visual Studio?

Select the text you want to automatically indent.Click menu Edit → Advanced → *Format Selection, or press Ctrl + K , Ctrl + F . Format Selection applies the smart indenting rules for the language in which you are programming to the selected text.


1 Answers

Add your this in your settings.json file

"[dart]": {
   "editor.defaultFormatter": "Dart-Code.dart-code",
   "editor.formatOnSave": true
},
like image 144
Haley Huynh Avatar answered Oct 21 '22 04:10

Haley Huynh