empty_map_pattern
A map pattern must have at least one entry.
Description
#The analyzer produces this diagnostic when a map pattern is empty.
Example
#The following code produces this diagnostic because the map pattern is empty:
dart
void f(Map<int, String> x) {
if (x case {}) {}
}
Common fixes
#If the pattern should match any map, then replace it with an object pattern:
dart
void f(Map<int, String> x) {
if (x case Map()) {}
}
If the pattern should only match an empty map, then check the length in the pattern:
dart
void f(Map<int, String> x) {
if (x case Map(isEmpty: true)) {}
}
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.