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 {}
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.