default_ value_ on_ required_ parameter
Required named parameters can't have a default value.
Description
#The analyzer produces this diagnostic when a named parameter has both the required
modifier and a default value. If the parameter is required, then a value for the parameter is always provided at the call sites, so the default value can never be used.
Example
#The following code generates this diagnostic:
dart
void log({required String message = 'no message'}) {}
Common fixes
#If the parameter is really required, then remove the default value:
dart
void log({required String message}) {}
If the parameter isn't always required, then remove the required
modifier:
dart
void log({String message = 'no message'}) {}
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.