list_ element_ type_ not_ assignable
Details about the 'list_element_type_not_assignable' diagnostic produced by the Dart analyzer.
The element type '{0}' can't be assigned to the list type '{1}'.
Description
#The analyzer produces this diagnostic when the type of an element in a list literal isn't assignable to the element type of the list.
Example
#
The following code produces this diagnostic because 2.5 is a double, and
the list can hold only integers:
List<int> x = [1, 2.5, 3];
Common fixes
#If you intended to add a different object to the list, then replace the element with an expression that computes the intended object:
List<int> x = [1, 2, 3];
If the object shouldn't be in the list, then remove the element:
List<int> x = [1, 3];
If the object being computed is correct, then widen the element type of the list to allow all of the different types of objects it needs to contain:
List<num> x = [1, 2.5, 3];
Unless stated otherwise, the documentation on this site reflects Dart 3.10.3. Report an issue.