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.

Additional resources:

Example

❌ Bad:

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

map.keys.contains('hello'); // LINT
}

✅ Good:

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

map.containsKey('hello');
}