【问题标题】:Dart format is weird in vscodeDart 格式在 vscode 中很奇怪
【发布时间】:2020-11-20 21:39:42
【问题描述】:

我的 dart 文件格式很奇怪

    return Scaffold(
        backgroundColor: bgColor,
        body: SafeArea(
            child: Container(
          decoration: BoxDecoration(
              image: DecorationImage(
                  image: AssetImage('assets/$bgImage'), fit: BoxFit.cover)),
          child: Padding(
            padding: const EdgeInsets.fromLTRB(0, 120, 0, 0),
            child: Column(
              children: <Widget>[
                FlatButton.icon(

如何进行设置,以便正常的小部件树可以正确缩进。

另外,我设置了“editor.rulers”:[120],这仍然给了我不想要的自动缩进:

                    onPressed: () async {
                      **dynamic result =
                          await Navigator.pushNamed(context, '/location');**
                      setState(() {
                        data = {
                          'time': result['time'],
                          'location': result['location'],
                          'flag': result['flag'],
                          'isDaytime': result['isDaytime']
                        };
                      });
                    },

【问题讨论】:

  • vs 代码告诉你把一个尾随逗号放在右边
  • 不是真的,vscode 那里没有警告或错误

标签: flutter dart visual-studio-code format vscode-settings


【解决方案1】:

在参数列表中使用尾随逗号。

没有尾随逗号:

Foo(arg1: ..., arg2: ...)

尾随逗号:

Foo(
  arg1: ...,
  arg2: ..., // notice the comma
)

例如:

decoration: BoxDecoration(
  image: DecorationImage(
    image: AssetImage('assets/$bgImage'), 
    fit: BoxFit.cover, // add a comma here
  ), // add a comma here
),

【讨论】:

  • decoration: BoxDecoration( 没有缩进的 ling。
  • 确保容器的参数列表以逗号结尾。
猜你喜欢
  • 2021-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-07
  • 2015-02-10
  • 1970-01-01
  • 1970-01-01
  • 2021-08-01
相关资源
最近更新 更多