dot_ shorthand_ missing_ context
A dot shorthand can't be used where there is no context type.
Description
#The analyzer produces this diagnostic when a dot shorthand is used where there is no context type.
Example
#
The following code produces this diagnostic because there is no context
type for the expression
.a
:
void f() {
var e = .a;
print(e);
}
enum E {a, b}
Common fixes
#
If you want to use a dot shorthand, then add a context type, which in this
example means adding the explicit type
E
to the local variable:
void f() {
E e = .a;
print(e);
}
enum E {a, b}
If you don't want to add a context type, then specify the name of the
type containing the member being referenced, which in this case is
E
:
void f() {
var e = E.a;
print(e);
}
enum E {a, b}
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.