set_element_type_not_assignable
The element type '{0}' can't be assigned to the set type '{1}'.
Description
#The analyzer produces this diagnostic when an element in a set literal has a type that isn't assignable to the element type of the set.
Example
#The following code produces this diagnostic because the type of the string
literal '0'
is String
, which isn't assignable to int
, the element
type of the set:
dart
var s = <int>{'0'};
Common fixes
#If the element type of the set literal is wrong, then change the element type of the set:
dart
var s = <String>{'0'};
If the type of the element is wrong, then change the element:
dart
var s = <int>{'0'.length};
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。