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');
}
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.