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

Flutter开发报错:No named parameter with the name 'controller' 求解决

解决Flutter TextField报错:Error: No named parameter with the name 'controller'

问题出在你把controller参数放在了InputDecoration内部,而实际上controller是TextField的直接属性,不属于decoration的配置项。

修改后的完整TextField代码如下:

TextField(
  keyboardType: TextInputType.number,
  // 将controller移至此处,作为TextField的顶层参数
  controller: nota1Controller,
  decoration: InputDecoration(
    labelText: "Nota 1",
    labelStyle: TextStyle(color: Colors.green),
  ),
  textAlign: TextAlign.center,
  style: TextStyle(color: Colors.green, fontSize: 25.0),
),

原因说明:
Flutter的TextField组件中,controller是用于绑定文本编辑控制器的顶层参数,和keyboardType、textAlign属于同一层级的配置。而InputDecoration仅负责配置输入框的外观样式,并不包含controller这个参数,所以你之前的写法会触发参数不存在的报错。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 02:15:36