undefined_extension_operator
The operator '{0}' isn't defined for the extension '{1}'.
Description
#The analyzer produces this diagnostic when an operator is invoked on a specific extension when that extension doesn't implement the operator.
Example
#The following code produces this diagnostic because the extension E
doesn't define the operator *
:
var x = E('') * 4;
extension E on String {}
Common fixes
#If the extension is expected to implement the operator, then add an implementation of the operator to the extension:
var x = E('') * 4;
extension E on String {
int operator *(int multiplier) => length * multiplier;
}
If the operator is defined by a different extension, then change the name of the extension to the name of the one that defines the operator.
If the operator is defined on the argument of the extension override, then remove the extension override:
var x = '' * 4;
extension E on String {}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。