whereBetween method
Filters the list to include only elements where the specified key's value is within the given range.
key
is the key to check.
start
is the lower bound of the range (inclusive).
end
is the upper bound of the range (inclusive).
Example:
final filteredList = list.whereBetween("age", 18, 30);
Implementation
List<T> whereBetween(String key, num start, num end) {
if (isEmpty) {
return <T>[];
}
return whereType<Map<String, dynamic>>()
.where((element) =>
element.containsKey(key) &&
element[key] is num &&
(element[key] as num) >= start &&
(element[key] as num) <= end)
.map((e) => e as T)
.toList();
}