unnecessary_ wildcard_ pattern
Unnecessary wildcard pattern.
Description
#
The analyzer produces this diagnostic when a wildcard pattern is used in
either an and (&&
) pattern or an or (||
) pattern.
Example
#
The following code produces this diagnostic because the wildcard pattern
(_
) will always succeed, making it's use in an and pattern unnecessary:
void f(Object? x) {
if (x case _ && 0) {}
}
Common fixes
#Remove the use of the wildcard pattern:
void f(Object? x) {
if (x case 0) {}
}
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.