map_entry_not_in_map
Map entries can only be used in a map literal.
Description
#The analyzer produces this diagnostic when a map entry (a key/value pair) is found in a set literal.
Example
#The following code produces this diagnostic because the literal has a map entry even though it's a set literal:
var collection = <String>{'a' : 'b'};
Common fixes
#If you intended for the collection to be a map, then change the code so that it is a map. In the previous example, you could do this by adding another type argument:
var collection = <String, String>{'a' : 'b'};
In other cases, you might need to change the explicit type from Set
to
Map
.
If you intended for the collection to be a set, then remove the map entry, possibly by replacing the colon with a comma if both values should be included in the set:
var collection = <String>{'a', 'b'};
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。