Dart Analyze logoDart Analyze/
DRT-W1544

Spread elements in map literals must implement 'Map'DRT-W1544

Major severityMajor
Bug Risk categoryBug Risk

The analyzer produces this diagnostic when the static type of the expression of a spread element that appears in a map literal doesn't implement the type Map.

Example

The following code produces this diagnostic because l isn't a Map:

var l =  <String>['a', 'b'];
var m = <int, String>{...l};

Common fixes

The most common fix is to replace the expression with one that produces a map:

var l =  <String>['a', 'b'];
var m = <int, String>{...l.asMap()};