pattern_ type_ mismatch_ in_ irrefutable_ context
The matched value of type '{0}' isn't assignable to the required type '{1}'.
Description
#The analyzer produces this diagnostic when the type of the value on the right-hand side of a pattern assignment or pattern declaration doesn't match the type required by the pattern being used to match it.
Example
#
The following code produces this diagnostic because
x
might not be a
String
and hence might not match the object pattern:
void f(Object x) {
var String(length: a) = x;
print(a);
}
Common fixes
#Change the code so that the type of the expression on the right-hand side matches the type required by the pattern:
void f(String x) {
var String(length: a) = x;
print(a);
}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.