const_constructor_param_type_mismatch
A value of type '{0}' can't be assigned to a parameter of type '{1}' in a const constructor.
Description
#The analyzer produces this diagnostic when the runtime type of a constant value can't be assigned to the static type of a constant constructor's parameter.
Example
#The following code produces this diagnostic because the runtime type of i
is int
, which can't be assigned to the static type of s
:
dart
class C {
final String s;
const C(this.s);
}
const dynamic i = 0;
void f() {
const C(i);
}
Common fixes
#Pass a value of the correct type to the constructor:
dart
class C {
final String s;
const C(this.s);
}
const dynamic i = 0;
void f() {
const C('$i');
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。