Visual Studio Code Flutter格式不适用于我的缩进空间值

问题描述 投票:0回答:1

我一整天都在浪费,我不知道发生了什么。我正在使用Visual Studio Code 1.40.2,正在学习Flutter 3.60。有时由于空间缩进,Flutter代码变得不可读。我只想创建更多的空间(缩进空间),但是当我使用format选项时,选项卡的大小又变成了2。我看了太多的网站,包括Stackoverflow,不幸的是我没有找到解决方案。这是我的配置文件:(感谢帮助)

{
"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,
},

}

  • 我更改了editor.insertSpaces的false和true,什么都没有改变。
  • editor.detectIndentation true或false无效。
  • 我添加了此块,但没有起作用。

    “ [flutter]”:{“ editor.tabSize”:6“ editor.insertSpaces”:是的,“ editor.detectIndentation”:否,},

这是我的简单代码:

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,
                ),
            ),
        ],
    );
  }
}

当我使用格式代码(Shift + alt + p)时,代码缩进空格或制表符的大小变成2,这会让我发疯。

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,
          ),
        ),
      ],
    );
  }
}
flutter dart visual-studio-code indentation
1个回答
0
投票

VS Code的Dart扩展使用Dart SDK(dart_style)中的格式化程序,该格式化程序不支持自定义缩进选项(通过设计),因此它将始终使用2个空格。

如果您希望手动进行格式化,则可以禁用内置格式化程序,并且其他VS Code扩展也可以为Dart提供格式化程序-尽管据我所知尚未创建(尽管如果有人对创建VS Code扩展感兴趣,我已经提供了帮助in this issue

© www.soinside.com 2019 - 2024. All rights reserved.