extension_as_expression
Extension '{0}' can't be used as an expression.
Description
#The analyzer produces this diagnostic when the name of an extension is used in an expression other than in an extension override or to qualify an access to a static member of the extension. Because classes define a type, the name of a class can be used to refer to the instance of Type
representing the type of the class. Extensions, on the other hand, don't define a type and can't be used as a type literal.
Example
#The following code produces this diagnostic because E
is an extension:
extension E on int {
static String m() => '';
}
var x = E;
Common fixes
#Replace the name of the extension with a name that can be referenced, such as a static member defined on the extension:
extension E on int {
static String m() => '';
}
var x = E.m();
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.