Skip to main content

prefer-wildcard-pattern

added in: 1.5.0
🛠
Dart 3.0+

Warns when a dynamic or Object type is used instead of a wildcard pattern.

Example

❌ Bad:

final object = WithField('hello');

final value = switch (object) {
WithField() => 'good',
Object() => 'bad', // LINT
dynamic() => 'bad', // LINT
};

✅ Good:

final object = WithField('hello');

final value = switch (object) {
WithField() => 'good',
_ => 'good',
};