Skip to main content

avoid-map-keys-contains

added in: 1.8.0
🛠
Pro+
preset: recommended

Warns when Map's .keys.contains is used instead of containsKey.

.keys.contains is 6000 times slower than containsKey and should be avoided.

Example

❌ Bad:

void main() {
final map = {'hello': 'world'};

// LINT: Avoid '.keys.contains'. Try using '.containsKey' instead.
map.keys.contains('hello');
}

✅ Good:

void main() {
final map = {'hello': 'world'};

map.containsKey('hello'); // Correct, uses 'containsKey'
}

Additional Resources