list_element_type_not_assignable
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];
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。