EN_raw_map_value_type_not_assignable

  •                   Toolschevron_right
    
  •                   Diagnosticschevron_right
    
  •                   map_value_type_not_assignable
    
                map_value_type_not_assignable
    

Details about the 'map_value_type_not_assignable' diagnostic produced by the Dart analyzer.

                more_vert
  •                       copyCopy link
    
  •                       bug_reportReport issue
    

The element type '{0}' can't be assigned to the map value type '{1}'.

              Description

              #

              The analyzer produces this diagnostic when a value of a key-value pair in a
              map literal has a type that isn't assignable to the value type of the
              map.

              Example

              #

              The following code produces this diagnostic because `2` is an `int`, but/
              the values of the map are required to be `String`s:

                dart
var m = <String, String>{'a': 2};
                content_copy

              Common fixes

              #

              If the type of the map is correct, then change the value to have the
              correct type:

                dart
var m = <String, String>{'a': '2'};
                content_copy

If the type of the value is correct, then change the value type of the map:

                dart
var m = <String, int>{'a': 2};
                content_copy

Was this page's content helpful?

                    thumb_up
                    thumb_down

                Unless stated otherwise, the documentation on this site reflects Dart 3.13.3. Report an issue.