pattern_ never_ matches_ value_ type
The matched value type '{0}' can never match the required type '{1}'.
Description
#The analyzer produces this diagnostic when the type of the object being matched can't ever be matched by the pattern.
Example
#
The following code produces this diagnostic because a
double
is being
matched by a pattern that requires an
int
, which can never succeed:
void f(String? s) {
if (s case int _) {}
}
Common fixes
#If one of the types is wrong, then change one or both of the types so that the pattern can succeed:
void f(String? s) {
if (s case String _) {}
}
If the types aren't wrong, then remove the pattern match:
void f(double x) {}
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.