containsMapKey method
Checks if any map in the list contains the specified entity key.
The entity parameter represents a map with a single key.
The function iterates through each item in the list, checking if any map
contains the first key from the entity map.
Returns true if any map in the list contains the specified entity key, false otherwise.
Example:
List<Map<String, dynamic>> maps = [
{'id': 1, 'name': 'Alice'},
{'id': 2, 'name': 'Bob'},
{'id': 3, 'name': 'Charlie'},
];
Map<String, dynamic> entity = {'id': 2};
bool containsKey = maps.containsMapKey(entity);
print(containsKey); // Output: true
Implementation
bool containsMapKey(Map entity) {
for (var item in this) {
Map e = item as Map;
if (e.containsKey(entity.keys.first)) {
return true;
}
}
return false;
}