wrong_ number_ of_ parameters_ for_ setter
Setters must declare exactly one required positional parameter.
Description
#The analyzer produces this diagnostic when a setter is found that doesn't declare exactly one required positional parameter.
Examples
#
The following code produces this diagnostic because the setter
s
declares
two required parameters:
class C {
set s(int x, int y) {}
}
The following code produces this diagnostic because the setter
s
declares
one optional parameter:
class C {
set s([int? x]) {}
}
Common fixes
#Change the declaration so that there's exactly one required positional parameter:
class C {
set s(int x) {}
}
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.