for_in_of_invalid_type
The type '{0}' used in the 'for' loop must implement '{1}'.
Description
#The analyzer produces this diagnostic when the expression following in
in a for-in loop has a type that isn't a subclass of Iterable
.
Example
#The following code produces this diagnostic because m
is a Map
, and Map
isn't a subclass of Iterable
:
dart
void f(Map<String, String> m) {
for (String s in m) {
print(s);
}
}
Common fixes
#Replace the expression with one that produces an iterable value:
dart
void f(Map<String, String> m) {
for (String s in m.values) {
print(s);
}
}
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.