default_value_in_function_type
Parameters in a function type can't have default values.
Description
#The analyzer produces this diagnostic when a function type associated with a parameter includes optional parameters that have a default value. This isn't allowed because the default values of parameters aren't part of the function's type, and therefore including them doesn't provide any value.
Example
#The following code produces this diagnostic because the parameter p
has a default value even though it's part of the type of the parameter g
:
void f(void Function([int p = 0]) g) {
}
Common fixes
#Remove the default value from the function-type's parameter:
void f(void Function([int p]) g) {
}
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.