invalid_extension_argument_count
Extension overrides must have exactly one argument: the value of 'this' in the extension method.
Description
#The analyzer produces this diagnostic when an extension override doesn't
have exactly one argument. The argument is the expression used to compute
the value of this
within the extension method, so there must be one
argument.
Examples
#The following code produces this diagnostic because there are no arguments:
dart
extension E on String {
String join(String other) => '$this $other';
}
void f() {
E().join('b');
}
And, the following code produces this diagnostic because there's more than one argument:
dart
extension E on String {
String join(String other) => '$this $other';
}
void f() {
E('a', 'b').join('c');
}
Common fixes
#Provide one argument for the extension override:
dart
extension E on String {
String join(String other) => '$this $other';
}
void f() {
E('a').join('b');
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。