【发布时间】:2020-08-20 10:18:30
【问题描述】:
我正在尝试使用颤振渲染小部件,但出现以下错误:
“无法为具有非最终字段的类定义 const 构造函数”
“常量构造函数不能调用State的非常量超级构造函数”
“名称参数‘键’未定义”
出现此错误的代码如下:
class ContainerButton extends StatefulWidget {
@override
ContainerButtonState createState() => ContainerButtonState();
}
class ContainerButtonState extends State<ContainerButton> {
final ButtonType buttonType;
const CustomButton({Key key, this.buttonType}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(21),
color: Color(0xfff4f5f9),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Flexible(
child: CustomButton(buttonType: ButtonType.download),
),
Flexible(
child: CustomButton(buttonType: ButtonType.share),
),
Flexible(
child: CustomButton(buttonType: ButtonType.problem),
),
],
),
);
}
}
我会很感激任何提示。谢谢,
【问题讨论】:
标签: flutter