equal_keys_in_const_map
Two keys in a constant map literal can't be equal.
Description
#The analyzer produces this diagnostic when a key in a constant map is the same as a previous key in the same map. If two keys are the same, then the second value would overwrite the first value, which makes having both pairs pointless.
Example
#The following code produces this diagnostic because the key 1
is used
twice:
dart
const map = <int, String>{1: 'a', 2: 'b', 1: 'c', 4: 'd'};
Common fixes
#If both entries should be included in the map, then change one of the keys to be different:
dart
const map = <int, String>{1: 'a', 2: 'b', 3: 'c', 4: 'd'};
If only one of the entries is needed, then remove the one that isn't needed:
dart
const map = <int, String>{1: 'a', 2: 'b', 4: 'd'};
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。