Where()
A Where() method is an extension provided by the Iterable class.
The where() method takes a callback function as an argument.
void main() {
Iterable<int> number = [1, 2, 3, 4];
Iterable even = number.where((number) => number.isEven);
print(even); //{2}
Iterable greaterThanFive = number.where((number) => number > 5);
print('Numbers greater than 5: $greaterThanFive');
Iterable<String> words = ['apple', 'banana', 'orange', 'pear', 'kiwi'];
Iterable longWords = words.where((word) => word.length > 5);
print('Long words: $longWords');
}
Output
(2, 4)
Numbers greater than 5: ()
Long words: (banana, orange)
Exited.