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:
var s = <int>{'0'};
Common fixes
#If the element type of the set literal is wrong, then change the element type of the set:
var s = <String>{'0'};
If the type of the element is wrong, then change the element:
var s = <int>{'0'.length};
Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.