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:
void log({required String message = 'no message'}) {}
Common fixes
#If the parameter is really required, then remove the default value:
void log({required String message}) {}
If the parameter isn't always required, then remove the
required
modifier:
void log({String message = 'no message'}) {}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.