Sco*_*ttF 2 code-formatting dart visual-studio-code flutter
我正在编写一些颤振代码。该代码将右大括号堆叠在同一行上。此外,当我在 VSCode 中运行“Format Document”时,它还会将大括号堆叠在一行上。
像这样(见最后一行)...
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();
}));
Run Code Online (Sandbox Code Playgroud)
但在 flutter 文档和示例代码中,所有示例都使用以下格式(其中大括号位于单独的行上)。
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();
}
)
);
Run Code Online (Sandbox Code Playgroud)
哪种格式才是正确的?另外,“格式化文档”是否使用 dart 扩展来获得正确的格式?
您可以在大括号末尾使用逗号 (,)。然后“格式文档”将分隔每个大括号的行。尝试这个:
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();
},
),
);
Run Code Online (Sandbox Code Playgroud)
编辑:
好的,您正在寻找正确的方法。正如官方文档中提到的,您应该使用尾随逗号。
为了获得良好的自动格式化效果,我们建议您采用可选的尾随逗号。
| 归档时间: |
|
| 查看次数: |
1288 次 |
| 最近记录: |