extra_positional_arguments_could_be_named
Too many positional arguments: {0} expected, but {1} found.
Description
#The analyzer produces this diagnostic when a method or function invocation has more positional arguments than the method or function allows, but the method or function defines named parameters.
Example
#The following code produces this diagnostic because f
defines 2 positional parameters but has a named parameter that could be used for the third argument:
void f(int a, int b, {int? c}) {}
void g() {
f(1, 2, 3);
}
Common fixes
#If some of the arguments should be values for named parameters, then add the names before the arguments:
void f(int a, int b, {int? c}) {}
void g() {
f(1, 2, c: 3);
}
Otherwise, remove the arguments that don't correspond to positional parameters:
void f(int a, int b, {int? c}) {}
void g() {
f(1, 2);
}
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.