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
相关产品推荐
相关产品推荐

