non_ constant_ set_ element
Details about the 'non_constant_set_element' diagnostic produced by the Dart analyzer.
The values in a const set literal must be constants.
Description
#The analyzer produces this diagnostic when a constant set literal contains an element that isn't a compile-time constant.
Example
#The following code produces this diagnostic because i isn't a constant:
var i = 0;
var s = const {i};
Common fixes
#If the element can be changed to be a constant, then change it:
const i = 0;
var s = const {i};
If the element can't be a constant, then remove the keyword const:
var i = 0;
var s = {i};
Unless stated otherwise, the documentation on this site reflects Dart 3.10.3. Report an issue.