const_with_non_constant_argument
Arguments of a constant creation must be constant expressions.
Description
#The analyzer produces this diagnostic when a const constructor is invoked with an argument that isn't a constant expression.
Example
#The following code produces this diagnostic because i
isn't a constant:
dart
class C {
final int i;
const C(this.i);
}
C f(int i) => const C(i);
Common fixes
#Either make all of the arguments constant expressions, or remove the
const
keyword to use the non-constant form of the constructor:
dart
class C {
final int i;
const C(this.i);
}
C f(int i) => C(i);
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。