You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter代码格式化后如何让末尾闭合括号逐行单独显示?

解决IntelliJ IDEA中Flutter代码闭合括号堆叠的格式化问题

按以下步骤调整IDE的Dart格式化设置,就能让每个闭合括号单独占一行:

  • 打开IDE设置(快捷键:Windows/Linux用Ctrl+Alt+S,Mac用Cmd+,)
  • 依次展开Languages & Frameworks → Dart
  • 在Formatter区域,勾选将每个闭合括号放在单独一行(英文界面为"Put each closing brace on its own line")
  • 点击Apply和OK保存设置
  • 选中代码后按格式化快捷键(Windows/Linux用Ctrl+Alt+L,Mac用Cmd+Option+L),即可得到目标格式

调整前的代码格式

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            backgroundColor: Colors.purple[50],
            appBar: AppBar(
              title: Text('I AM RICH'),
              backgroundColor: Colors.purple,
            ),
            body: Center(
                child: Image(
              image: NetworkImage(
                  'https://df2sm3urulav.cloudfront.net/tenants/gr/uploads/content/4wmnqlctgu0f3c9a.jpg'),
            ))));
  }
}

调整后的代码格式

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            backgroundColor: Colors.purple[50],
            appBar: AppBar(
              title: Text('I AM RICH'),
              backgroundColor: Colors.purple,
            ),
            body:  Center(
               child: Image(
                  image: NetworkImage(
                      'https://df2sm3urulav.cloudfront.net/tenants/gr/uploads/content/4wmnqlctgu0f3c9a.jpg'),
                )
            )
        )
    );
  }
}

内容的提问来源于stack exchange,提问作者Jayesslee

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 18:05:18