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

Flutter布局报错:未用const调用却提示构造函数非const的解决方法

问题修复方案

报错的根源不是TextFormField,而是你给InputDecoration加了const修饰,但它内部的OutlineInputBorder构造函数并不是const构造,没法在const上下文中使用,所以才会触发这个错误。

修复方法很简单,只需要去掉所有InputDecoration前面的const关键字即可,修改后的代码如下:

Column(
    children: [
      ListTile(
        title: Text('Full Name'),
        subtitle: TextFormField(
          decoration: InputDecoration(
            border: OutlineInputBorder(
                borderRadius: BorderRadius.all(Radius.circular(8))),
            hintText: 'Full Name',
          ),
        ),
      ),
      SizedBox(
        height: 5,
      ),
      Row(
        children: [
          Expanded(
            child: ListTile(
        title: Text('Department'),
        subtitle: TextFormField(
              decoration: InputDecoration(
                border: OutlineInputBorder(
                    borderRadius: BorderRadius.all(Radius.circular(8))),
                hintText: '  Department',
              ),
            ),),
          ),
          SizedBox(
            width: 5,
          ),
          Expanded(
            child:ListTile(
        title: Text('Year Of Study'),
        subtitle:  TextFormField(
              decoration: InputDecoration(
                border: OutlineInputBorder(
                    borderRadius: BorderRadius.all(Radius.circular(8))),
                hintText: '  Year Of Study',
              ),
            ),),
          ),
        ],
      )
    ],
  ),

如果确实需要使用const装饰器,可以换成支持const构造的边框(比如UnderlineInputBorder),但这不符合你要的圆角外边框需求,所以优先选择去掉const的方案。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 06:35:14