non_ constant_ map_ pattern_ key
Details about the 'non_constant_map_pattern_key' diagnostic produced by the Dart analyzer.
Key expressions in map patterns must be constants.
Description
#The analyzer produces this diagnostic when a key in a map pattern isn't a constant expression.
Example
#
The following code produces this diagnostic because the key A() isn't a
constant:
void f(Object x) {
if (x case {A(): 0}) {}
}
class A {
const A();
}
Common fixes
#Use a constant for the key:
void f(Object x) {
if (x case {const A(): 0}) {}
}
class A {
const A();
}
Unless stated otherwise, the documentation on this site reflects Dart 3.10.3. Report an issue.