Issue
I have a map looks like this
Map<String, String> vaccinated = {
'dog': 'ready',
'cat': 'ready',
'mouse': 'done',
'horse': 'done',
};
and I would like to count only 'done' inside the map and wants a result of
2
but the thing I've tried showed me is only boolean anyone knows how can I count specific values inside map
Solution
You can do it like
void main() {
Map<String, String> vaccinated = {
'dog': 'ready',
'cat': 'ready',
'mouse': 'done',
'horse': 'done',
};
final total =
vaccinated.entries.where((e) => e.value == "done").toList().length;
print(total);
}
More about Map
Answered By - Yeasin Sheikh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.