gpt4 book ai didi

flutter - 正确的抖动/Dart 格式

转载 作者:行者123 更新时间:2023-12-03 03:30:07 25 4
gpt4 key购买 nike

我正在编写一些波动代码。代码将在同一行上的右括号括起来。另外,当我在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();
}));
但是在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();
}
)
);
哪种格式正确?另外,“格式化文档”是否使用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();
},
),
);
编辑:
好的,您正在寻找正确的方法。如 official document中所述,您应该使用结尾逗号。

To get good automatic formatting, we recommend you adopt the optional trailing commas.

关于flutter - 正确的抖动/Dart 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64543548/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com