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
:
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');
}
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.