so im working on company project and realize the widget doesn't need Key? and required costructor, and when i try to make it like that it occur red underline.
my project i want to remove the required and '?'
example of what i want
CodePudding user response:
you have probably defined height as final and that's why it is asking it.
define height as
double? height
CodePudding user response:
It should view like that:
class CustomButton extends StatelessWidget {
final double? height;
final double width;
final String title;
final double margin;
final Function() onPressed;
const CustomButton ({
Key? key,
this.height,
required this.width,
required this.title,
required this.margin,
required this.onPressed,
}) : super (key: key);
}
CodePudding user response:
You have to pass an initial value for the CustomButton
height property.
class CustomButton extends StatelessWidget {
final double height;
final double width;
final String title;
final double margin;
final Function() onPressed;
const CustomButton ({
Key? key,
this.height = 100,
required this.width,
required this.title,
required this.margin,
required this.onPressed,
}) : super (key: key);
}