non_constant_set_element
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:
dart
var i = 0;
var s = const {i};
Common fixes
#If the element can be changed to be a constant, then change it:
dart
const i = 0;
var s = const {i};
If the element can't be a constant, then remove the keyword const
:
dart
var i = 0;
var s = {i};
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。