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