non_constant_map_pattern_key
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:
dart
void f(Object x) {
if (x case {A(): 0}) {}
}
class A {
const A();
}
Common fixes
#Use a constant for the key:
dart
void f(Object x) {
if (x case {const A(): 0}) {}
}
class A {
const A();
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。