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

Flutter代码报错:Expected ',' before this 解决方案咨询

Flutter错误"Expected ',' before this"解决办法

你的代码报错是因为Scaffold组件的appBar属性末尾缺少逗号,Dart语法要求类的多个命名参数之间必须用逗号分隔,appBar的闭合括号后没加逗号,导致编译器无法识别后面的body参数,从而抛出语法错误。

修正方法很简单,在appBar的AppBar(...)闭合括号后面添加逗号即可:

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: Text('New project', style: TextStyle(fontSize:25, color: Colors.green, decorationStyle: TextDecorationStyle.dotted)),
    ), // 此处添加逗号
    body: Center(
      child: Column(
        children: <Widget>[
          Text('How many times pushed'),
          Text('ok')
        ],
      ),
    ),
  );
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 03:55:15