I am trying to render a widget with flutter and I am getting the following errors:
"can't define a const constructor for a class with non final fields"
"constant constructor can't call non-constant super constructor of State"
"The name parameter 'Key' ins't defined"
The code with this errors is the following:
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),
),
],
),
);
}
}
I would appreciate any hint. Thank you,
According to error, just remove the const
keyword from Constructor and you are good to go. The Following code should remove the error :
class ContainerButtonState extends State<ContainerButton> {
final ButtonType buttonType;
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),
),
],
),
);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With