const_ constructor_ param_ type_ mismatch
Details about the 'const_constructor_param_type_mismatch' diagnostic produced by the Dart analyzer.
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:
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:
class C {
final String s;
const C(this.s);
}
const dynamic i = 0;
void f() {
const C('$i');
}
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.