Skip to main content

avoid-redundant-pragma-inline

added in: 1.4.0
🛠
preset: recommended

Warns when a @pragma('vm:prefer-inline') annotation has no effect.

The Dart compiler can't inline certain methods, even if they are annotated with @pragma("vm:prefer-inline"). Those include methods with a try block, methods declared async, async*, sync* and certain core library methods.

Additional info:

Example

❌ Bad:

class SomeClass {
('vm:prefer-inline')
Future<String> good() {
return Future.value('hello');
}

('vm:prefer-inline') // LINT
Future<void> asyncMethod() async {
await good();
}

('vm:prefer-inline') // LINT
void methodWithTry() {
try {
// ...
} catch (_) {
print('error');
}
}
}

✅ Good:

class SomeClass {
('vm:prefer-inline')
Future<String> good() {
return Future.value('hello');
}

Future<void> asyncMethod() async {
await good();
}

void methodWithTry() {
try {
// ...
} catch (_) {
print('error');
}
}
}