正确的抖动/飞镖格式

时间:2020-10-26 19:11:04

标签: flutter dart visual-studio-code code-formatting

我正在处理一些混乱的代码。代码将在同一行上的右括号括起来。另外,当我在VSCode中运行“格式文档”时,它也会将花括号堆积在一行上。

像这样(请参阅最后一行)...

return Container(
    width: 200,
    child: CupertinoTextField(
        maxLength: 10,
        textCapitalization: TextCapitalization.characters,
        focusNode: focusNode,
        decoration: BoxDecoration(
            border: Border.all(color: Colors.white.withOpacity(0))),
        style: accentTextStyle,
        placeholder: "NAME",
        textAlign: TextAlign.center,
        keyboardAppearance: Brightness.dark,
        controller: _textController,
        onChanged: (s) {
          navigation.update();
          if (s == '') {
            program.name = 'UNNAMED${navigation.programsCounter}';
            return;
          }
          program.name = s.toUpperCase();
        }));

但是在复杂的文档和示例代码中,所有示例均使用以下格式(大括号位于单独的行中)。

return Container(
  width: 200,
  child: CupertinoTextField(
    maxLength: 10,
    textCapitalization: TextCapitalization.characters,
    focusNode: focusNode,
    decoration: BoxDecoration(
        border: Border.all(color: Colors.white.withOpacity(0))),
    style: accentTextStyle,
    placeholder: "NAME",
    textAlign: TextAlign.center,
    keyboardAppearance: Brightness.dark,
    controller: _textController,
    onChanged: (s) {
      navigation.update();
      if (s == '') {
        program.name = 'UNNAMED${navigation.programsCounter}';
        return;
      }
      program.name = s.toUpperCase();
    }
  )
);

哪种格式正确?另外,“格式化文档”是否使用dart扩展名来获取正确的格式?

2 个答案:

答案 0 :(得分:2)

您可以在大括号的末尾使用逗号(,)。然后,“格式文档”将分隔每个括号的行。试试这个:

@page
@model IndexModel
@{
    ViewData["Title"] = "Home page";
}

<head runat="server">
    <script>
        gr.init({
            selector: 'textarea#record',
            height: 500,
            width: 25,
            view_style: 'body { font-size:14px }'
        });
    </script>
</head>

<div class="text-center">
    <h1 class="display-4">GAME PORTAL</h1>
    <p>GAME</p>
    <div id="gameContainer">
        <textarea id="record" asp-for="game" cols="25" rows="3"></textarea>
    </div>
</div>

编辑:

好的,您正在寻找正确的方法。如official document中所述,您应该使用尾部逗号。

为获得良好的自动格式设置,我们建议您采用可选的尾随逗号。

答案 1 :(得分:0)

您还可以通过在括号之间添加services <- read.table(header = TRUE, text = " animal_id service_date 610710 2005-10-22 610710 2006-12-03 610710 2006-12-27 610710 2007-12-02 610710 2008-01-17 610710 2008-03-04") services$service_date <- as.Date(services$service_date) events <- read.table(header = TRUE, text = " animal_id event_date event_description 610710 2006-06-16 PP 610710 2007-02-15 PP 610710 2008-01-09 PN 610710 2008-04-09 PP 610710 2009-06-16 PP") events$event_date <- as.Date(events$event_date) events$event_date_lag <- ave(events$event_date, events$animal_id, FUN=function(a) c(a[1][NA], a[-length(a)])) events # animal_id event_date event_description event_date_lag # 1 610710 2006-06-16 PP <NA> # 2 610710 2007-02-15 PP 2006-06-16 # 3 610710 2008-01-09 PN 2007-02-15 # 4 610710 2008-04-09 PP 2008-01-09 # 5 610710 2009-06-16 PP 2008-04-09 并单击缩进按钮来获得相同的缩进:

  • VS代码:commas
  • Android Studio:alt + shift + f

对我来说很好用:)

添加如下逗号:

ctrl + alt + l

缩进后:

onChanged: (s) {
          navigation.update();
          if (s == '') {
            program.name = 'UNNAMED${navigation.programsCounter}';
            return;
          }
          program.name = s.toUpperCase();
        },),);
相关问题