If I delete required
from the named parameters, it gives me an error:
The parameter 'color' // can't have a value of 'null' because of its type, but the implicit default value is 'null'.
What is the difference between them and when do we need to use them?
class RoundedButton extends StatelessWidget {
late final Color color;
final String title;
final VoidCallback? onPressedInput;
RoundedButton(
{required this.color,
required this.title,
@required this.onPressedInput});
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.symmetric(vertical: 16.0),
child: Material(
color: color,
borderRadius: BorderRadius.circular(30.0),
elevation: 5.0,
child: MaterialButton(
onPressed: onPressedInput,
minWidth: 200.0,
height: 42.0,
child: Text(
title,
),
),
),
);
}
}
@required
again, and should instead always userequired
when you have a non-nullable named parameter. – Cerebrovascular